How to burn tokens, and approve/revoke token delegations on Nexis Native Chain.
spl-token
library, use the burn
function.
burn
function requires the following arguments:
connection
- the JSON-RPC connection to the clusterpayer
- the account of the payer for the transactionaccount
- the token account to burn tokens frommint
- the token mint associated with the token accountowner
- the account of the owner of the token accountamount
- the amount of tokens to burnburn
function creates a transaction with instructions
obtained from the createBurnInstruction
function:
spl-token
library, you use the approve
function.
approve
function returns a TransactionSignature
that can be viewed on
Nexis Native Chain Explorer. The approve
function requires the following arguments:
connection
- the JSON-RPC connection to the clusterpayer
- the account of the payer for the transactionaccount
- the token account to delegate tokens fromdelegate
- the account the owner is authorizing to transfer or burn tokensowner
- the account of the owner of the token accountamount
- the maximum number of tokens the delegate may transfer or burnapprove
function creates a transaction with instructions
obtained from the createApproveInstruction
function:
spl-token
library, you use the revoke
function.
revoke
function returns a TransactionSignature
that can be viewed on
Nexis Native Chain Explorer. The revoke
function requires the following arguments:
connection
- the JSON-RPC connection to the clusterpayer
- the account of the payer for the transactionaccount
- the token account to revoke the delegate authority fromowner
- the account of the owner of the token accountrevoke
function creates a transaction with instructions
obtained from the createRevokeInstruction
function:
approve
from spl-token
to authorize a delegate to transfer or burn
up to 50 tokens from our token account.
Just like Transferring Tokens in the
previous lab, you can
add a second account on devnet
if you like, or find a friend who has a devnet account!
Create a new file delegate-tokens.ts
delegate
using the spl-token
library’s revoke
function.
Revoke will set delegate for the token account to null and reset the delegated
amount to 0.
All we will need for this function is the token account and user. After the
spl-token
library’s burn
function to remove half of your tokens from
circulation.
Now call this new function in main
to burn 25 of the user’s tokens.