Burn Native Tokens
You may want to burn some of your circulating native tokens. To do so, you will need to call the
Account.burn_native_token(native_token, options)
function.
If you burn your native tokens, you will not be able to destroy the foundry that created them. If you want to destroy the foundry in the future, you should consider melting your native tokens
Code Example
Before you run the code example, make sure to update the token ID with one which is available in your account. If you haven't done so already, you can follow the how to mint a native token guide. If you don't know the token ID you can check your accounts balance to retrieve the available native tokens in your account.
The following example will:
- Create an account manager.
- Get Alice's account which was created in the first guide.
- Get the account's balance.
- Burn 1 native tokens of the supplied ID.
- Rust
- Nodejs
- Python
- Java
This example uses dotenv, which is not safe for use in production environments.
loading...
Run the example by running the following command:
cargo run --example burn_native_token --release
loading...
You can run the example by running the following command from the wallet/bindings/nodejs/examples/
folder:
node 31-burn-native-token.js
loading...
loading...
Expected Output
- Rust
- Nodejs
- Python
- Java
Balancebeforeburning:
AccountBalance{
base_coin: BaseCoinBalance{
total: 209995515000,
available: 209995515000
},
required_storage_deposit: 1787500,
native_tokens: [
NativeTokensBalance{
token_id: TokenId(0x08adbd5f0844fdc9bf4eafe2df929ac42cc90336e68da284cce96f22523bd87cde0300000000),
total: 100,
available: 100
}
],
nfts: [
],
aliases: [
AliasId(0xadbd5f0844fdc9bf4eafe2df929ac42cc90336e68da284cce96f22523bd87cde)
],
foundries: [
FoundryId(0x08adbd5f0844fdc9bf4eafe2df929ac42cc90336e68da284cce96f22523bd87cde0200000000),
FoundryId(0x08adbd5f0844fdc9bf4eafe2df929ac42cc90336e68da284cce96f22523bd87cde0100000000),
FoundryId(0x08adbd5f0844fdc9bf4eafe2df929ac42cc90336e68da284cce96f22523bd87cde0300000000)
],
potentially_locked_outputs: {
OutputId(0x452a212cbe8512ea7844759402f1679bc1c1e6a088f1f3faaed6aeaa0ac246ee0000): false,
OutputId(0xb8572c3386616ae4be668a46756fcc46bf9cdf178bd50122cf70c81dbec362200000): false,
OutputId(0x041a90dc4d9b23a3ef91c64b7aa69da27e90d3306f644fc7b1647016925d5ff30000): false,
OutputId(0xcb30fa5cbb34b7bb10c0408b4e2bbe323b73fcb9b30b0a9446c1866210cf82d80000): false,
OutputId(0x2c0a9874a309ac3ffce684a8d5f38be54f12760d40ef8fd72f043a11fd4b76110000): false
}
}
Balanceafterburning:
AccountBalance{
base_coin: BaseCoinBalance{
total: 209995515000,
available: 209995515000
},
required_storage_deposit: 1787500,
native_tokens: [
NativeTokensBalance{
token_id: TokenId(0x08adbd5f0844fdc9bf4eafe2df929ac42cc90336e68da284cce96f22523bd87cde0300000000),
total: 99,
available: 99
}
],
nfts: [
],
aliases: [
AliasId(0xadbd5f0844fdc9bf4eafe2df929ac42cc90336e68da284cce96f22523bd87cde)
],
foundries: [
FoundryId(0x08adbd5f0844fdc9bf4eafe2df929ac42cc90336e68da284cce96f22523bd87cde0200000000),
FoundryId(0x08adbd5f0844fdc9bf4eafe2df929ac42cc90336e68da284cce96f22523bd87cde0100000000),
FoundryId(0x08adbd5f0844fdc9bf4eafe2df929ac42cc90336e68da284cce96f22523bd87cde0300000000)
],
potentially_locked_outputs: {
OutputId(0x2c0a9874a309ac3ffce684a8d5f38be54f12760d40ef8fd72f043a11fd4b76110000): false,
OutputId(0x452a212cbe8512ea7844759402f1679bc1c1e6a088f1f3faaed6aeaa0ac246ee0000): false,
OutputId(0x041a90dc4d9b23a3ef91c64b7aa69da27e90d3306f644fc7b1647016925d5ff30000): false,
OutputId(0xb8572c3386616ae4be668a46756fcc46bf9cdf178bd50122cf70c81dbec362200000): false,
OutputId(0xcb30fa5cbb34b7bb10c0408b4e2bbe323b73fcb9b30b0a9446c1866210cf82d80000): false
}
}
{
payload: {
type: 6,
essence: {
type: 1,
networkId: '1856588631910923207',
inputs: [Array],
inputsCommitment: '0xbbeedfa08b1136421e6c0ad599ada29ccadd326535262de9edadbfe9475b29cf',
outputs: [Array]
},
unlocks: [ [Object] ]
},
blockId: '0xf6bba8d67f6f35bc63658f12df5649f71cbc28512e4f3aa65fda727fa2ae4e5b',
inclusionState: 'Pending',
timestamp: '1671182074342',
transactionId: '0x13df212d5f8ae281226543d7888491f866fbe669b160a9d2893674ff1a00a81a',
networkId: '1856588631910923207',
incoming: false,
note: null
}
Check your block on http://localhost:14265/api/core/v2/blocks/0xf6bba8d67f6f35bc63658f12df5649f71cbc28512e4f3aa65fda727fa2ae4e5b
{
"payload": {
"type": 6,
"essence": {
"type": 1,
"networkId": "1856588631910923207",
"inputs": [
{
"type": 0,
"transactionId": "0xcbcfbbd9b36bd9a3d6830311ed428036d13fc37050bcd1cf82fb4e4b695570fd",
"transactionOutputIndex": 2
}
],
"inputsCommitment": "0x3f44d0e0f31bd57f028d80d8c9b07b0e12406e6cd5b2e8b6ed0abd178a1e1b1b",
"outputs": [
{
"type": 3,
"amount": "57600",
"nativeTokens": [
{
"id": "0x08429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef0300000000",
"amount": "0x10"
}
],
"unlockConditions": [
{
"type": 0,
"address": {
"type": 0,
"pubKeyHash": "0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
}
}
]
}
]
},
"unlocks": [
{
"type": 0,
"signature": {
"type": 0,
"publicKey": "0xde3152ce9d67415b9c5a042ea01caccc3f73ff1c0c77036874cb8badf9798d56",
"signature": "0xfd9964cdcfa6bda25419968c3d74d29e35611bbc2a9ddad2be0eadc816da270fcf739c2e7ecc4be4e46f33b32aa37370534e0ee322c23755ecb608de9618ae0a"
}
}
]
},
"blockId": "0xb53140f385372ca247d7d66ee14755a2e18d8ca750fd85122a6b5b6b0c1abf7c",
"inclusionState": "Pending",
"timestamp": "1664885731096",
"transactionId": "0xbb7f884e81ed32dbfe4f9c880b0f6577c9c90744b7ab33d84950706d2924c18c",
"networkId": "1856588631910923207",
"incoming": false
}
{
"payload": {
"type": 6,
"essence": {
"type": 1,
"networkId": "1856588631910923207",
"inputs": [
{
"type": 0,
"transactionId": "0xcbcfbbd9b36bd9a3d6830311ed428036d13fc37050bcd1cf82fb4e4b695570fd",
"transactionOutputIndex": 2
}
],
"inputsCommitment": "0x3f44d0e0f31bd57f028d80d8c9b07b0e12406e6cd5b2e8b6ed0abd178a1e1b1b",
"outputs": [
{
"type": 3,
"amount": "57600",
"nativeTokens": [
{
"id": "0x08429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef0300000000",
"amount": "0x10"
}
],
"unlockConditions": [
{
"type": 0,
"address": {
"type": 0,
"pubKeyHash": "0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
}
}
]
}
]
},
"unlocks": [
{
"type": 0,
"signature": {
"type": 0,
"publicKey": "0xde3152ce9d67415b9c5a042ea01caccc3f73ff1c0c77036874cb8badf9798d56",
"signature": "0xfd9964cdcfa6bda25419968c3d74d29e35611bbc2a9ddad2be0eadc816da270fcf739c2e7ecc4be4e46f33b32aa37370534e0ee322c23755ecb608de9618ae0a"
}
}
]
},
"blockId": "0xb53140f385372ca247d7d66ee14755a2e18d8ca750fd85122a6b5b6b0c1abf7c",
"inclusionState": "Pending",
"timestamp": "1664885731096",
"transactionId": "0xbb7f884e81ed32dbfe4f9c880b0f6577c9c90744b7ab33d84950706d2924c18c",
"networkId": "1856588631910923207",
"incoming": false
}