Destroy a Foundry
You can destroy a foundry by calling the Account.destroy_foundry(foundry_id, options)
function. The function will
destroy a foundry output as long as its circulating
native token supply is zero. Any native tokens
which were minted by other foundries will be sent to the controlling
alias.
Code Example
Before you run the example you should update the foundry_id
to one available in your account that has no available
native tokens. If you have no available
foundries, you can create one by minting a native token. If you've already minted your
tokens but need to empty the foundry, you can decrease your native token supply by melting them.
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 a foundry 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.
loading...
Run the example by running the following command:
cargo run --example destroy_foundry --release
loading...
You can run the example by running the following command from the wallet/bindings/nodejs/examples/
folder:
node 32-destroy-foundry.js
loading...
loading...
Expected Output
- Rust
- Nodejs
- Python
- Java
Balancebeforedestroying: AccountBalance{
base_coin: BaseCoinBalance{
total: 109999491000,
available: 109999491000
},
required_storage_deposit: 3046500,
native_tokens: [
...
],
nfts: [
...
]
aliases: [
...
],
foundries: [
FoundryId(0x086d7755dc84a6757ea28285990ddac2eb53f558f8345507ac76d0c33caacaf8970100000000),
],
potentially_locked_outputs: {
...
}
}Balanceafterdestroying: AccountBalance{
base_coin: BaseCoinBalance{
total: 109999491000,
available: 109999491000
},
required_storage_deposit: 3046500,
native_tokens: [
...
],
nfts: [
...
]
aliases: [
...
],
foundries: [
],
potentially_locked_outputs: {
...
}
}
{
payload: {
type: 6,
essence: {
type: 1,
networkId: '1856588631910923207',
inputs: [Array],
inputsCommitment: '0x3179afe33825e2c9557079291324968a159b6f8b89d0c7478ae3ec38b3b00548',
outputs: [Array]
},
unlocks: [ [Object], [Object] ]
},
blockId: '0xeff7d964dea61e303d92e1a4930d42268e8e7d0a19f53f7a929518cb9e57a50f',
inclusionState: 'Pending',
timestamp: '1671182397354',
transactionId: '0x6de7c4366f0419a6cbc2a39f8d67f0b6e5737b8caa8c029f59cee486b36ab8e9',
networkId: '1856588631910923207',
incoming: false,
note: null
}
Check your block on http://localhost:14265/api/core/v2/blocks/0xeff7d964dea61e303d92e1a4930d42268e8e7d0a19f53f7a929518cb9e57a50f
loading...
{
"payload": {
"type": 6,
"essence": {
"type": 1,
"networkId": "1856588631910923207",
"inputs": [
{
"type": 0,
"transactionId": "0x27df04eac1408b4ec758f6aa222d616b21d9b237789e601d9d0b81aa6466fa97",
"transactionOutputIndex": 0
},
{
"type": 0,
"transactionId": "0x27df04eac1408b4ec758f6aa222d616b21d9b237789e601d9d0b81aa6466fa97",
"transactionOutputIndex": 1
}
],
"inputsCommitment": "0x06e8bdc8ddf5dac739e620f815aade7f73d06a33a911e1e6956d1f8d087ad6e3",
"outputs": [
{
"type": 4,
"amount": "103100",
"aliasId": "0x429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef",
"stateIndex": 9,
"stateMetadata": "0x",
"foundriesCounter": 0,
"unlockConditions": [
{
"type": 4,
"address": {
"type": 0,
"pubKeyHash": "0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
}
},
{
"type": 5,
"address": {
"type": 0,
"pubKeyHash": "0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
}
}
]
}
]
},
"unlocks": [
{
"type": 0,
"signature": {
"type": 0,
"publicKey": "0xde3152ce9d67415b9c5a042ea01caccc3f73ff1c0c77036874cb8badf9798d56",
"signature": "0xb0a0473eb7dc09231707b11a04ad3a2fee9d67dd83f00e27ddbdc11f4473080ff8ac9a78d5dfb83da8bf1e8e77dc5c6cd867a28dc7520dc0f01dd49ce7815a02"
}
},
{
"type": 2,
"reference": 0
}
]
},
"blockId": "0xf76fc85a74e1ac5381ff25777fef8a1c9ffb98bdad83157151bc8804bf496861",
"inclusionState": "Pending",
"timestamp": "1664886716685",
"transactionId": "0xce5504e02bf0796e48143d5daa1753500e798dbab673e14bb671512750f7d03a",
"networkId": "1856588631910923207",
"incoming": false
}