Burn Instruction
Permanently destroys tokens by removing them from circulation. This reduces the total supply of the token.
Before we can burn any token, we'll need to already have:
- Initialized a
Mint
account. - A
Token
account orAssociated Token
account that already has at least the amount we want to burn.
Raw Instruction
By using just "raw" instruction without any abstraction, this is how burning a token would look like:
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
This is how the same instructions would look like abstracted away with the burn()
instruction:
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`)