Skip to main content

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

Replace the native token ID

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:

  1. Create an account manager.
  2. Get Alice's account which was created in the first guide.
  3. Get the account's balance.
  4. Burn an NFT of the supplied ID.
Dotenv

This example uses dotenv, which is not safe for use in production environments.

// Copyright 2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

//! cargo run --example burn_nft --release
// In this example we will burn an existing nft output
// Rename `.env.example` to `.env` first

use std::{env, str::FromStr};

use dotenv::dotenv;
use iota_client::block::output::NftId;
use iota_wallet::{account_manager::AccountManager, Result};

#[tokio::main]
async fn main() -> Result<()> {
// This example uses dotenv, which is not safe for use in production
dotenv().ok();

// Create the account manager
let manager = AccountManager::builder().finish().await?;

// Get the account we generated with `01_create_wallet`
let account = manager.get_account("Alice").await?;

let balance = account.balance().await?;
println!("Balance before burning:\n{balance:?}",);

// Set the stronghold password
manager
.set_stronghold_password(&env::var("STRONGHOLD_PASSWORD").unwrap())
.await?;

// Replace with an NftId that is available in the account
let nft_id = NftId::from_str("0xe192461b30098a5da889ef6abc9e8130bf3b2d980450fa9201e5df404121b932")?;
let transaction = account.burn_nft(nft_id, None).await?;

account
.retry_transaction_until_included(&transaction.transaction_id, None, None)
.await?;

let balance = account.sync(None).await?;

println!("Balance after burning:\n{balance:?}",);

Ok(())
}

Run the example by running the following command:

cargo run --example burn_nft --release

Expected Output

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: {

}
}