Skip to main content

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:

  1. Create an account manager.
  2. Get Alice's account which was created in the first guide.
  3. Get the account's balance.
  4. Destroy an alias output by id.
  5. Get the account's balance again to show the difference after step 4.
Dotenv

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

wallet/examples/16_destroy_alias.rs
loading...

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

Expected Output

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: [
],
[...]
}