Files
SHiNE-server/shine-solana/shine/create-SHiNE-DAO/scripts/07_execute_mint_nft.js
T

39 lines
1.9 KiB
JavaScript

#!/usr/bin/env node
"use strict";
const path = require("path");
const { Connection, PublicKey, Transaction, sendAndConfirmTransaction } = require("@solana/web3.js");
const { TOKEN_2022_PROGRAM_ID, getAssociatedTokenAddressSync, createAssociatedTokenAccountIdempotentInstruction, createMintToInstruction } = require("@solana/spl-token");
const { PROGRAM_VERSION_V3, withExecuteTransaction } = require("@solana/spl-governance");
const { clusterUrl, loadKeypair, parseEnvConfig, resolveConfigPath, toInstructionData } = require("./js_common");
async function main() {
const cfg = parseEnvConfig(resolveConfigPath(process.argv[2], "nft-flow.config.env"));
const proposal = new PublicKey(process.argv[3]);
const proposalTx = new PublicKey(process.argv[4]);
const target = new PublicKey(process.argv[5]);
const nftMint = new PublicKey(process.argv[6]);
if (!process.argv[6]) throw new Error("Usage: node 07_execute_mint_nft.js <config.env> <proposal> <proposalTx> <targetWallet> <nftMint>");
const conn = new Connection(clusterUrl(cfg.CLUSTER), "confirmed");
const main = loadKeypair(path.resolve(__dirname, "..", cfg.MAIN_KEYPAIR));
const governance = new PublicKey(cfg.GOVERNANCE);
const govPid = new PublicKey(cfg.SPL_GOVERNANCE_PROGRAM_ID);
const targetAta = getAssociatedTokenAddressSync(nftMint, target, false, TOKEN_2022_PROGRAM_ID);
const mintIx = [
createAssociatedTokenAccountIdempotentInstruction(main.publicKey, targetAta, target, nftMint, TOKEN_2022_PROGRAM_ID),
createMintToInstruction(nftMint, targetAta, governance, 1n, [], TOKEN_2022_PROGRAM_ID),
].map(toInstructionData);
const ix = [];
await withExecuteTransaction(ix, govPid, PROGRAM_VERSION_V3, governance, proposal, proposalTx, mintIx);
const sig = await sendAndConfirmTransaction(conn, new Transaction().add(...ix), [main], { commitment: "confirmed" });
console.log("Mint execute done:", sig);
}
main().catch((e) => {
console.error(e?.message || e);
process.exit(1);
});