import {
MINT_SIZE,
TOKEN_2022_PROGRAM_ID,
createInitializeMint2Instruction,
getMinimumBalanceForRentExemptMint,
} from "@solana/spl-token";
// Generate a new keypair for the mint account
const mint = new Keypair();
// Calculate rent-exempt balance for mint account
const rentLamports = await getMinimumBalanceForRentExemptMint(pg.connection);
// Create instruction for new account
const createAccountInstruction = SystemProgram.createAccount({
fromPubkey: pg.wallet.publicKey,
newAccountPubkey: mint.publicKey,
space: MINT_SIZE,
lamports: rentLamports,
programId: TOKEN_2022_PROGRAM_ID,
});
// Create instruction to initialize the mint
const initializeMintInstruction = createInitializeMint2Instruction(
mint.publicKey, // mint account
2, // decimals
pg.wallet.publicKey, // mint authority
pg.wallet.publicKey, // freeze authority
TOKEN_2022_PROGRAM_ID
);
// Combine both instructions into one transaction
const transaction = new Transaction().add(
createAccountInstruction,
initializeMintInstruction
);
// Send and confirm the transaction
const transactionSignature = await sendAndConfirmTransaction(
pg.connection,
transaction,
[pg.wallet.keypair, mint] // Both keypairs needed
);
console.log(
"\nTransaction Signature:",
`https://explorer.fc.devnet.soo.network/tx/${transactionSignature}`
);
console.log(
"\nMint Account:",
`https://explorer.fc.devnet.soo.network/address/${mint.publicKey}`
);