Skip to main content

Lesson

Finally, we’ll cover burning tokens, and delegation. You may not use these in your own application, so if you’re really excited about NFTs, feel free to skip to creating NFTs with Metaplex!

Burn Tokens

Burning tokens is the process of decreasing the token supply of a given token mint. Burning tokens removes the tokens from the given token account and from broader circulation. To burn tokens using the spl-token library, use the burn function.
The burn function requires the following arguments:
  • connection - the JSON-RPC connection to the cluster
  • payer - the account of the payer for the transaction
  • account - the token account to burn tokens from
  • mint - the token mint associated with the token account
  • owner - the account of the owner of the token account
  • amount - the amount of tokens to burn
Under the hood, the burn function creates a transaction with instructions obtained from the createBurnInstruction function:

Approve Delegate

Approving a delegate is the process of authorizing another account to transfer or burn tokens from a token account. When using a delegate, the authority over the token account remains with the original owner. The maximum amount of tokens a delegate may transfer or burn is specified at the time the owner of the token account approves the delegate. Note that there can only be one delegate account associated with a token account at any given time. To approve a delegate using the spl-token library, you use the approve function.
The 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 cluster
  • payer - the account of the payer for the transaction
  • account - the token account to delegate tokens from
  • delegate - the account the owner is authorizing to transfer or burn tokens
  • owner - the account of the owner of the token account
  • amount - the maximum number of tokens the delegate may transfer or burn
Under the hood, the approve function creates a transaction with instructions obtained from the createApproveInstruction function:

Revoke Delegate

A previously approved delegate for a token account can be later revoked. Once a delegate is revoked, the delegate can no longer transfer tokens from the owner’s token account. Any remaining amount left untransferred from the previously approved amount can no longer be transferred by the delegate. To revoke a delegate using the spl-token library, you use the revoke function.
The 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 cluster
  • payer - the account of the payer for the transaction
  • account - the token account to revoke the delegate authority from
  • owner - the account of the owner of the token account
Under the hood, the revoke function creates a transaction with instructions obtained from the createRevokeInstruction function:

Lab

This lab extends the lab from the previous chapter.

1. Delegating tokens

Let’s use 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

2. Revoke Delegate

Lets revoke the 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

3. Burn Tokens

Finally, let’s remove some tokens from circulation by burning them. Use 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.
Well done! You’ve now

Completed the lab?

Push your code to GitHub and tell us what you thought of this lesson!