Mint To Instruction
Erstellt neue Tokens und hinterlegt sie in einem bestimmten Konto. Nur die Mint-Autorität kann diese Operation durchführen.
Bevor wir Tokens prägen können, benötigen wir bereits:
Ein initialisiertes
MintKonto, für das wir diemintAuthoritybesitzenEin initialisiertes
TokenKonto oderAssociated TokenKonto, in das wir die Tokens prägen werden
Raw Instruction
Bei Verwendung der "rohen" Anweisung ohne Abstraktion würde das Prägen eines Tokens so aussehen:
ts
const destination = Keypair.generate();
const tokenAccount = await getAssociatedTokenAddress(
mint.publicKey,
destination.publicKey,
);
// Create ATA creation instruction
const createAtaInstruction = createAssociatedTokenAccountIdempotentInstruction(
keypair.publicKey, // payer
tokenAccount, // associated token account address
destination.publicKey, // owner
mint.publicKey, // mint
);
// Mint tokens to ATA
const mintToInstruction = createMintToInstruction(
mint.publicKey, // mint
tokenAccount, // destination
keypair.publicKey, // mint authority
1_000e6, // amount of tokens
);
const transaction = new Transaction().add(
createAtaInstruction,
mintToInstruction,
);
const signature = await sendAndConfirmTransaction(connection, transaction, [keypair]);
console.log(`Token accounts created and tokens minted! Check out your TX here: https://explorer.solana.com/tx/${signature}?cluster=devnet`);Abstracted Instruction
So würden die gleichen Anweisungen aussehen, wenn sie mit der mintTo() Anweisung abstrahiert werden:
ts
const destination = Keypair.generate();
const ata = await getOrCreateAssociatedTokenAccount(
connection,
keypair,
mint,
destination.publicKey
);
console.log(`This is your ATA: ${ata.address}!`)
let tx = await mintTo(
connection,
keypair,
mint,
ata.address,
keypair.publicKey,
1e6,
);
console.log(`Succesfully Minted!. Transaction Here: https://explorer.solana.com/tx/${tx}?cluster=devnet`)