销毁指令
通过将代币从流通中移除,永久销毁代币。这将减少代币的总供应量。
在我们销毁任何代币之前,我们需要已经拥有:
- 一个已初始化的
Mint
账户。 - 一个
Token
账户或Associated Token
账户,并且该账户中至少有我们想要销毁的数量。
原始指令
仅使用“原始”指令而没有任何抽象时,销毁代币的操作如下:
// Burn tokens to ATA
const burnInstruction = createBurnInstruction(
tokenAccount, // token account
mint, // mint
keypair.publicKey // owner
1e6, // amount
);
const transaction = new Transaction().add(burnInstruction);
const signature = await sendAndConfirmTransaction(connection, transaction, [keypair]);
console.log(`Tokens Burned! Check out your TX here: https://explorer.solana.com/tx/${signature}?cluster=devnet`);
抽象指令
以下是使用 burn()
指令抽象后的操作:
let tx = await burn(
connection, // connection
keypair, // payer
tokenAccount, // token account
keypair.publicKey, // owner of the token account
1e6, // amount to transfer
);
console.log(`Succesfully Burned!. Transaction Here: https://explorer.solana.com/tx/${tx}?cluster=devnet`)