Typescript
使用Web3.js的SPL代幣

使用Web3.js的SPL代幣

燒毀指令

永久銷毀代幣,將其從流通中移除。這會減少代幣的總供應量。

在我們燒毀任何代幣之前,我們需要已經擁有:

  • 已初始化的Mint帳戶。

  • 一個Token帳戶或Associated Token帳戶,且該帳戶已經擁有至少我們想要燒毀的數量。

我們燒毀的代幣數量是根據小數位數進行「標準化」的。這意味著,如果我們想燒毀一個有6位小數的代幣,我們實際需要輸入1e6作為數量。

Raw Instruction

僅使用「原始」指令而不進行任何抽象化,燒毀代幣的操作如下:

ts
// 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`);

Abstracted Instruction

以下是使用burn()指令進行抽象化後的操作:

ts
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`)

Checked Instruction

Blueshift © 2025Commit: e573eab