Melt Native Tokens
You may want to melt some of your circulating native tokens. To do so, you will need to call the
Account.melt_native_token(native_token, options)
function.
If you melt your native tokens, you can still destroy the foundry that created them.
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.
- Melt 10 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 melt_native_token --release
loading...
You can run the example by running the following command from the wallet/bindings/nodejs/examples/
folder:
node 30-decrease-native-token-supply.js
loading...
loading...
Expected Output
- Rust
- Nodejs
- Python
- Java
{
payload: {
type: 6,
essence: {
type: 1,
networkId: '1856588631910923207',
inputs: [Array],
inputsCommitment: '0x2d6b40731bd6222d0f7670ea5a1b143e499703cf71fd51a821d32d91a77a5041',
outputs: [Array]
},
unlocks: [ [Object], [Object], [Object] ]
},
blockId: '0x350a89dad8a6d96dc5cd5e7abcafa334c287e14ee4187c0260d7b24209b4ff19',
inclusionState: 'Pending',
timestamp: '1671182041013',
transactionId: '0xd7b94f8487a817bc70febb80d83f0df93f1d7035851affaf7114cd7348cb610d',
networkId: '1856588631910923207',
incoming: false,
note: null
}
Check your block on http://localhost:14265/api/core/v2/blocks/0x350a89dad8a6d96dc5cd5e7abcafa334c287e14ee4187c0260d7b24209b4ff19
{
"payload": {
"type": 6,
"essence": {
"type": 1,
"networkId": "1856588631910923207",
"inputs": [
{
"type": 0,
"transactionId": "0xbd9dc768e5676e9d141ab96622143127328c10361f319f919365c480972dbe83",
"transactionOutputIndex": 0
},
{
"type": 0,
"transactionId": "0xbd9dc768e5676e9d141ab96622143127328c10361f319f919365c480972dbe83",
"transactionOutputIndex": 1
},
{
"type": 0,
"transactionId": "0xbd9dc768e5676e9d141ab96622143127328c10361f319f919365c480972dbe83",
"transactionOutputIndex": 2
}
],
"inputsCommitment": "0xaea8c0e6b4af1afb241b9d4b850b54438dff3e5dfe36a54f1bbaccdc81d1b245",
"outputs": [
{
"type": 4,
"amount": "50300",
"aliasId": "0x429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef",
"stateIndex": 6,
"stateMetadata": "0x",
"foundriesCounter": 0,
"unlockConditions": [
{
"type": 4,
"address": {
"type": 0,
"pubKeyHash": "0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
}
},
{
"type": 5,
"address": {
"type": 0,
"pubKeyHash": "0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
}
}
]
},
{
"type": 5,
"amount": "52800",
"serialNumber": 3,
"tokenScheme": {
"type": 0,
"mintedTokens": "0x17",
"meltedTokens": "0x2",
"maximumSupply": "0x64"
},
"unlockConditions": [
{
"type": 6,
"address": {
"type": 8,
"aliasId": "0x429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef"
}
}
]
},
{
"type": 3,
"amount": "57600",
"nativeTokens": [
{
"id": "0x08429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef0300000000",
"amount": "0x15"
}
],
"unlockConditions": [
{
"type": 0,
"address": {
"type": 0,
"pubKeyHash": "0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
}
}
]
}
]
},
"unlocks": [
{
"type": 0,
"signature": {
"type": 0,
"publicKey": "0xde3152ce9d67415b9c5a042ea01caccc3f73ff1c0c77036874cb8badf9798d56",
"signature": "0xc9c5369388d5fce9297c816612af93eea35b34d1fd4575de9b5ba5f477186e84f2affe6a2ba230beb1d47e3e5ee31f20d484a857e9c3d18fe0fe5e334d6f1202"
}
},
{
"type": 2,
"reference": 0
},
{
"type": 1,
"reference": 0
}
]
},
"blockId": "0x063c35701e459cb6515cd0be7d0ed691fd622f5a2dc3bb126213a4f06910ab54",
"inclusionState": "Pending",
"timestamp": "1664885556280",
"transactionId": "0xcbcfbbd9b36bd9a3d6830311ed428036d13fc37050bcd1cf82fb4e4b695570fd",
"networkId": "1856588631910923207",
"incoming": false
}
{
"payload": {
"type": 6,
"essence": {
"type": 1,
"networkId": "1856588631910923207",
"inputs": [
{
"type": 0,
"transactionId": "0xbd9dc768e5676e9d141ab96622143127328c10361f319f919365c480972dbe83",
"transactionOutputIndex": 0
},
{
"type": 0,
"transactionId": "0xbd9dc768e5676e9d141ab96622143127328c10361f319f919365c480972dbe83",
"transactionOutputIndex": 1
},
{
"type": 0,
"transactionId": "0xbd9dc768e5676e9d141ab96622143127328c10361f319f919365c480972dbe83",
"transactionOutputIndex": 2
}
],
"inputsCommitment": "0xaea8c0e6b4af1afb241b9d4b850b54438dff3e5dfe36a54f1bbaccdc81d1b245",
"outputs": [
{
"type": 4,
"amount": "50300",
"aliasId": "0x429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef",
"stateIndex": 6,
"stateMetadata": "0x",
"foundriesCounter": 0,
"unlockConditions": [
{
"type": 4,
"address": {
"type": 0,
"pubKeyHash": "0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
}
},
{
"type": 5,
"address": {
"type": 0,
"pubKeyHash": "0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
}
}
]
},
{
"type": 5,
"amount": "52800",
"serialNumber": 3,
"tokenScheme": {
"type": 0,
"mintedTokens": "0x17",
"meltedTokens": "0x2",
"maximumSupply": "0x64"
},
"unlockConditions": [
{
"type": 6,
"address": {
"type": 8,
"aliasId": "0x429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef"
}
}
]
},
{
"type": 3,
"amount": "57600",
"nativeTokens": [
{
"id": "0x08429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef0300000000",
"amount": "0x15"
}
],
"unlockConditions": [
{
"type": 0,
"address": {
"type": 0,
"pubKeyHash": "0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
}
}
]
}
]
},
"unlocks": [
{
"type": 0,
"signature": {
"type": 0,
"publicKey": "0xde3152ce9d67415b9c5a042ea01caccc3f73ff1c0c77036874cb8badf9798d56",
"signature": "0xc9c5369388d5fce9297c816612af93eea35b34d1fd4575de9b5ba5f477186e84f2affe6a2ba230beb1d47e3e5ee31f20d484a857e9c3d18fe0fe5e334d6f1202"
}
},
{
"type": 2,
"reference": 0
},
{
"type": 1,
"reference": 0
}
]
},
"blockId": "0x063c35701e459cb6515cd0be7d0ed691fd622f5a2dc3bb126213a4f06910ab54",
"inclusionState": "Pending",
"timestamp": "1664885556280",
"transactionId": "0xcbcfbbd9b36bd9a3d6830311ed428036d13fc37050bcd1cf82fb4e4b695570fd",
"networkId": "1856588631910923207",
"incoming": false
}