Destroy an Alias Output
You can destroy an alias output by ID using the Account.destroy_alias(alias_id, options)
function. If the alias still owns any outputs when you try to destroy it, you will get an error.
Code Example
The following example will:
- Create an account manager.
- Get Alice's account which was created in the first guide.
- Get the account's balance.
- Destroy an alias output by id.
- Get the account's balance again to show the difference after step 4.
- Rust
- Nodejs
- Python
- Java
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 destroy_alias --release
// In this example we will destroy an existing alias output. This is only possible if possible foundry outputs have
// circulating supply of 0. Rename `.env.example` to `.env` first
use std::{env, str::FromStr};
use dotenv::dotenv;
use iota_client::block::output::AliasId;
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 destroying:\n{balance:?}",);
// Set the stronghold password
manager
.set_stronghold_password(&env::var("STRONGHOLD_PASSWORD").unwrap())
.await?;
// Replace with an AliasId that is available in the account
let alias_id = AliasId::from_str("0x57f1bafae0ef43190597a0dfe72ef1477b769560203c1854c6fb427c486e6530")?;
let transaction = account.destroy_alias(alias_id, None).await?;
account
.retry_transaction_until_included(&transaction.transaction_id, None, None)
.await?;
let balance = account.sync(None).await?;
println!("Balance after destroying:\n{balance:?}",);
Ok(())
}
Before you run the example you should update the alias_id
to one available in your account.
Run the example by running the following command:
cargo run --example destroy_alias --release
This how to guide is not available in your language of choice at the moment. Please feel free to browse more examples which may suit your requirements.
This how to guide is not available in your language of choice at the moment. Please feel free to browse more examples which may suit your requirements.
// Copyright 2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
import org.iota.Wallet;
import org.iota.types.*;
import org.iota.types.account_methods.SyncAccount;
import org.iota.types.exceptions.InitializeWalletException;
import org.iota.types.exceptions.WalletException;
import org.iota.types.ids.AliasId;
import org.iota.types.ids.account.AccountAlias;
import org.iota.types.secret.StrongholdSecretManager;
public class DestroyAliasOutput {
public static void main(String[] args) throws WalletException, InterruptedException, InitializeWalletException {
// This example assumes that a wallet has already been created using the ´SetupWallet.java´ example.
// If you haven't run the ´SetupWallet.java´ example yet, you must run it first to be able to load the wallet as shown below:
Wallet wallet = new Wallet(new WalletConfig()
.withClientOptions(new ClientConfig().withNodes(Env.NODE))
.withSecretManager(new StrongholdSecretManager(Env.STRONGHOLD_PASSWORD, null, Env.STRONGHOLD_VAULT_PATH))
.withCoinType(CoinType.Shimmer)
.withStoragePath(Env.STORAGE_PATH)
);
// Get account and sync it with the registered node to ensure that its balances are up-to-date.
AccountHandle a = wallet.getAccount(new AccountAlias(Env.ACCOUNT_NAME));
a.syncAccount(new SyncAccount().withOptions(new SyncOptions()));
// TODO: replace with your own values.
AliasId aliasId = new AliasId("0xc3dc87b11c94ae919aae950309194bd145d8bf3a80824a63c24336dced7cb22f");
// Send transaction.
Transaction t = a.destroyAlias(new org.iota.types.account_methods.DestroyAlias().withAliasId(
aliasId
));
// Print transaction.
System.out.println(t);
// In case you are done and don't need the wallet instance anymore you can destroy the instance to clean up memory.
// For this, check out the ´DestroyWallet.java´ example.
}
}
Expected Output
- Rust
- Nodejs
- Python
- Java
Balancebeforedestroying: AccountBalance{
base_coin: BaseCoinBalance{
total: 109999491000,
available: 109999491000
},
required_storage_deposit: 3155000,
native_tokens: [
...
],
nfts: [
NftId(0x346cf240e9e56132295b0d648fde7037ad0b2e43a35c46668313e1be2970c08c),
NftId(0x79862038299b19b704c10da655afedd77c930278ae56f7a4cb9bca4bf6dd7313)
],
aliases: [
AliasId(0x0aa4fe362b61da2d4c11909162939c0fe20913e2edf5c12ea15cf92f6b36ef60),
],
[...]
}
Balanceafterdestroying: AccountBalance{
base_coin: BaseCoinBalance{
total: 109999491000,
available: 109999491000
},
required_storage_deposit: 3155000,
native_tokens: [
...
],
nfts: [
NftId(0x346cf240e9e56132295b0d648fde7037ad0b2e43a35c46668313e1be2970c08c),
NftId(0x79862038299b19b704c10da655afedd77c930278ae56f7a4cb9bca4bf6dd7313)
],
aliases: [
],
[...]
}
This how to guide is not available in your language of choice at the moment. Please feel free to browse more examples which may suit your requirements.
This how to guide is not available in your language of choice at the moment. Please feel free to browse more examples which may suit your requirements.
{
"payload":{
"type":6,
"essence":{
"type":1,
"networkId":"1856588631910923207",
"inputs":[
{
"type":0,
"transactionId":"0xef3c9f8e8179e133f8207f3933039eaaf601f1f260b6116d7ca7c6711baa91a8",
"transactionOutputIndex":0
}
],
"inputsCommitment":"0xebda3754c942e47e7dd0e9177ad24c2985b4db98009a58ee2417e69695c8afc5",
"outputs":[
{
"type":3,
"amount":"103100",
"unlockConditions":[
{
"type":0,
"address":{
"type":0,
"pubKeyHash":"0xcb89e7952f758942e4e623708ebd1512e11bd5b39abc53f082ef8a9c20ac760a"
}
}
]
}
]
},
"unlocks":[
{
"type":0,
"signature":{
"type":0,
"publicKey":"0x8deb59df30fdd61349c20987179b5e0268e34338f37841b816f62e66820dae6c",
"signature":"0x0740d0b4435c25c0b57d579c90d2dd1a197b18b95a9784a1fc04ce51e63b2f93f680ec3568751a8cae09eaf3f5ee4fad2543f3a6ada14501af091d94d103a70f"
}
}
]
},
"blockId":"0x3f86a22d6170b64a420562a8e31adcd515a6d2b15d0201f60e20fc037b9ec455",
"inclusionState":"Pending",
"timestamp":"1664966791558",
"transactionId":"0xf4f21680774c74ae44d3244aca8cc3fd0248930561de673032afb21b18b04e8e",
"networkId":"1856588631910923207",
"incoming":false
}