Інструкція Mint To
Створює нові токени та депонує їх на вказаний рахунок. Цю операцію може виконувати лише орган емісії.
Перш ніж ми зможемо емітувати будь-який токен, нам потрібно вже мати:
Ініціалізований рахунок
Mint, для якого ми маємоmintAuthorityІніціалізований рахунок
Tokenабо рахунокAssociated Token, на який ми збираємося емітувати токени
Raw Instruction
Використовуючи лише "сиру" інструкцію без будь-якої абстракції, емісія токена виглядатиме так:
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`,
);Expand
[12 more lines]
Abstracted Instruction
Ось як ті самі інструкції виглядатимуть з абстракцією за допомогою інструкції mintTo():
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`,
);Expand
[1 more lines]