Burn NFTs
You may want to burn some of your circulating NFTs. To do so, you will need to call the
Account.burn_nft(native_token, options)
function.
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 an NFT 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_nft --release
loading...
You can run the example by running the following command from the wallet/bindings/nodejs/examples/
folder:
node 27-burn-nft.js
loading...
You can run the example by running the following command from the binding/python/examples
folder:
python3 burn-nft.py
loading...
Expected Output
- Rust
- Nodejs
- Python
- Java
Balance before burning:
AccountBalance{
base_coin: BaseCoinBalance{
total: 209996955000,
available: 209996955000
},
required_storage_deposit: 902500,
native_tokens: [
],
nfts: [
NftId(0xe314d76664f0ffe8d5fbe670527f108328c14bc8dad89b234dde3ff8deb58ec9)
],
aliases: [
],
foundries: [
],
potentially_locked_outputs: {
}
}
Balance after burning:
AccountBalance{
base_coin: BaseCoinBalance{
total: 209996955000,
available: 209996955000
},
required_storage_deposit: 852000,
native_tokens: [
],
nfts: [
],
aliases: [
],
foundries: [
],
potentially_locked_outputs: {
}
}
{
payload: {
type: 6,
essence: {
type: 1,
networkId: '1856588631910923207',
inputs: [Array],
inputsCommitment: '0x8ed6de2d3570269b4cfe2eb7ad29ee324c1b6ff78ad1f608db2b4e40c03db366',
outputs: [Array]
},
unlocks: [ [Object] ]
},
blockId: '0x2ea37ddeeaad7e6546e22cb92821ada3a213760b6a799c49b68d57a287d68a3b',
inclusionState: 'Pending',
timestamp: '1663000414059',
transactionId: '0x8e178dddc6c65be31ebe9fc980add3a62573d972a15deee03ac2434fc91812c5',
networkId: '1856588631910923207',
incoming: false,
note: null
}
Check your block on http://localhost:14265/api/core/v2/blocks/0x2ea37ddeeaad7e6546e22cb92821ada3a213760b6a799c49b68d57a287d68a3b
{
"payload": {
"type": 6,
"essence": {
"type": 1,
"networkId": "1856588631910923207",
"inputs": [
{
"type": 0,
"transactionId": "0xf5e022f199d90f2020ab941de947368e9d02a4f05139fcb44f66feade216f150",
"transactionOutputIndex": 0
}
],
"inputsCommitment": "0xd64acb6fec68315c200484458fb0a2c1e9b7d06106aecdcb9c86403d955ad69a",
"outputs": [
{
"type": 3,
"amount": "52000",
"unlockConditions": [
{
"type": 0,
"address": {
"type": 0,
"pubKeyHash": "0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
}
}
]
}
]
},
"unlocks": [
{
"type": 0,
"signature": {
"type": 0,
"publicKey": "0xde3152ce9d67415b9c5a042ea01caccc3f73ff1c0c77036874cb8badf9798d56",
"signature": "0xd602074065070b6dada7ce8f5a3c0181a2662443e6e71d7599dcf1464ac04938bdb9b2a39e1f36152cd3226840ab8d63c77d4035a30407ab029b607a7ff4d108"
}
}
]
},
"blockId": "0x6bc73ef16d51924154fecf4cc2da1b14297b1aa75ff5261800ab88411185d7c2",
"inclusionState": "Pending",
"timestamp": "1664876190299",
"transactionId": "0x9c26110d611ea78fc0542dca45834abb35497c5ec6045448713f5a588e7f4292",
"networkId": "1856588631910923207",
"incoming": false
}
{
"payload": {
"type": 6,
"essence": {
"type": 1,
"networkId": "1856588631910923207",
"inputs": [
{
"type": 0,
"transactionId": "0xf5e022f199d90f2020ab941de947368e9d02a4f05139fcb44f66feade216f150",
"transactionOutputIndex": 0
}
],
"inputsCommitment": "0xd64acb6fec68315c200484458fb0a2c1e9b7d06106aecdcb9c86403d955ad69a",
"outputs": [
{
"type": 3,
"amount": "52000",
"unlockConditions": [
{
"type": 0,
"address": {
"type": 0,
"pubKeyHash": "0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
}
}
]
}
]
},
"unlocks": [
{
"type": 0,
"signature": {
"type": 0,
"publicKey": "0xde3152ce9d67415b9c5a042ea01caccc3f73ff1c0c77036874cb8badf9798d56",
"signature": "0xd602074065070b6dada7ce8f5a3c0181a2662443e6e71d7599dcf1464ac04938bdb9b2a39e1f36152cd3226840ab8d63c77d4035a30407ab029b607a7ff4d108"
}
}
]
},
"blockId": "0x6bc73ef16d51924154fecf4cc2da1b14297b1aa75ff5261800ab88411185d7c2",
"inclusionState": "Pending",
"timestamp": "1664876190299",
"transactionId": "0x9c26110d611ea78fc0542dca45834abb35497c5ec6045448713f5a588e7f4292",
"networkId": "1856588631910923207",
"incoming": false
}