Mint Native Tokens
You can use a node running the stardust update to mint
native tokens.
To do so, you will only need to add some funds to your account, define
the native token's options and call the Account.mint_native_token(native_token_options, options)
function.
Online Faucet
You can request test funds from the Shimmer Testnet Faucet.
Code Example
The following example will:
- Create an account manager.
- Get Alice's which was created in the first guide.
- Create the
NativeTokenOptions
. - Mint the native token by calling the
Account.mint_native_token(native_token_options, options)
function.
- Rust
- Nodejs
- Python
- Java
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 mint_native_token --release
// In this example we will mint a native token
// Rename `.env.example` to `.env` first
use std::env;
use dotenv::dotenv;
use iota_wallet::{account_manager::AccountManager, NativeTokenOptions, Result, U256};
#[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?;
account.sync(None).await?;
// Set the stronghold password
manager
.set_stronghold_password(&env::var("STRONGHOLD_PASSWORD").unwrap())
.await?;
// First create an alias output, this needs to be done only once, because an alias can have many foundry outputs
let transaction = account.create_alias_output(None, None).await?;
println!(
"Transaction: {} Block sent: {}/api/core/v2/blocks/{}",
transaction.transaction_id,
&env::var("NODE_URL").unwrap(),
transaction.block_id.expect("no block created yet")
);
// Wait for transaction to get included
account
.retry_transaction_until_included(&transaction.transaction_id, None, None)
.await?;
account.sync(None).await?;
let native_token_options = NativeTokenOptions {
alias_id: None,
circulating_supply: U256::from(100),
maximum_supply: U256::from(100),
foundry_metadata: None,
};
let transaction = account.mint_native_token(native_token_options, None).await?;
println!(
"Transaction: {} Block sent: {}/api/core/v2/blocks/{}",
transaction.transaction.transaction_id,
&env::var("NODE_URL").unwrap(),
transaction.transaction.block_id.expect("no block created yet")
);
Ok(())
}
Run the example by running the following command:
cargo run --example mint_native_token --release
/**
* This example mints native tokens
*/
const getUnlockedManager = require('./account-manager');
async function run() {
try {
const manager = await getUnlockedManager();
const account = await manager.getAccount('0');
await account.sync();
// First create an alias output, this needs to be done only once, because an alias can have many foundry outputs.
let tx = await account.createAliasOutput()
console.log('Transaction ID: ', tx.transactionId);
// Wait for transaction inclusion
await new Promise(resolve => setTimeout(resolve, 5000));
await account.sync();
// If we omit the AccountAddress field the first address of the account is used by default
const nativeTokenOptions = {
// Hello in bytes
foundryMetadata: '0x48656c6c6f',
circulatingSupply: '0x64',
maximumSupply: '0x64',
};
let { transaction } = await account.mintNativeToken(
nativeTokenOptions,
);
console.log('Transaction ID: ', transaction.transactionId);
} catch (error) {
console.log('Error: ', error);
}
process.exit(0);
}
run();
You can run the example by running the following command from the wallet/bindings/nodejs/examples/
folder:
node 22-mint-native-tokens.js
from iota_wallet import IotaWallet
import time
# In this example we will mint native tokens
wallet = IotaWallet('./alice-database')
account = wallet.get_account('Alice')
# Sync account with the node
response = account.sync()
print(f'Synced: {response}')
wallet.set_stronghold_password("some_hopefully_secure_password")
transaction = account.create_alias_output(None, None)
# Wait a few seconds for the transaction to get confirmed
time.sleep(7)
account.sync()
native_token_options = {
# 1000 hex encoded
"circulatingSupply": "0x3e8",
"maximumSupply": "0x3e8",
"foundryMetadata": "0xab",
}
transaction = account.mint_native_token(native_token_options, None)
print(f'Sent transaction: {transaction}')
You can run the example by running the following command from the binding/python/examples
folder:
python3 7-mint-native-tokens.py
// 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.account.AccountAlias;
import org.iota.types.secret.StrongholdSecretManager;
public class MintNativeToken {
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()));
// Fund the account for this example.
ExampleUtils.fundAccount(a);
// TODO: replace with your own values.
NativeTokenOptions options = new NativeTokenOptions();
options.withCirculatingSupply("0x20"); // number 23 hex encoded
options.withMaximumSupply("0x45"); // number 69 hex encoded
// Send transaction.
MintTokenTransaction t = a.mintNativeToken(new org.iota.types.account_methods.MintNativeToken().withNativeTokenOptions(options));
// 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
Transaction: 0xaa9737fb4007e8b0f4c181d6923b0e3547ae178c23c25233985bb22f61c84de7
Block sent: http://localhost:14265/api/core/v2/blocks/0x807dbdde107008dcc9acae29a0e32c261590bef13e5f5d8d3bb60949e633abd8
Transaction ID: 0x4cd9cca67165b3ae5160e5b3bad5a677d93140e3692c378ed5c661160e37ce09
Synced:{
'baseCoin':{
'total':'3302230302',
'available':'3302230302'
},
'requiredStorageDeposit':'910310000',
'nativeTokens':[
{
'tokenId':'0x08b83d49922e341d2cb45159707cfafdc9dc8fdb9d119543480dbaa5773eed8c4a0100000000',
'total':'0x64',
'available':'0x64'
}
],
'nfts':[
'0x17f97185f80fa56eab974de6b7bbb80fa812d4e8e37090d166a0a41da129cebc',
'0xdc8be91d779aac048aa9001ab99ecf12cf62a4701185a95f6206a1a201bfbe7c',
'0x1e808b7c6e603aaeb5f718881a74fedae72981ac7d5f0294eb561cad0e653566',
'0x3f0e11e9d9f48a57d0fba43d7d1158ee673cb8055f80a5ce45ad174c962c0d8a',
'0x77133189021f50d8d66e0678e553af9f46a832a24239653d3555edb8dc859e1f',
'0xceae643ff7c112a3adce8f55f7953ba0707ade21256a7a09068c0b47f7c62c5b',
'0x1b670afba8d59a445cbaf167f1fda05879362e3ea034f5c4a0979fbeb5a3964b'
],
'aliases':[
'0xa5526c4a15558b709340822edf00cb348d8606a27e2e59b00432a0afe8afb74d',
'0xf9c702ffe50c35d331b2df02295c2cc6d92f883530ff231bd76d1f6a72cb1d95',
'0x97eb7a447cd62e1c373ff8188ba422f5c1b0687707d38e10e8366a1c20d33fea'
],
'foundries':[
],
'potentiallyLockedOutputs':{
'0x850c1e43dff1a28a42d71edc6d4ad0b9f251c03993f9b0684a34f645514ffe270000':False
}
}
Sent transaction:{
'tokenId':'0x08a5526c4a15558b709340822edf00cb348d8606a27e2e59b00432a0afe8afb74d0100000000',
'transaction':{
'payload':{
'type':6,
'essence':{
'type':1,
'networkId':'1856588631910923207',
'inputs':[
{
'type':0,
'transactionId':'0x8defcb4d5bc2dd45ca616b01d87399eef5bde2bfb4d9f33695a0cab78cb731f0',
'transactionOutputIndex':0
},
{
'type':0,
'transactionId':'0x0220b5247654d05529f40b3d8cdb7ca6f89627038f47a68aa578b9e675ddc937',
'transactionOutputIndex':29
},
{
'type':0,
'transactionId':'0x0220b5247654d05529f40b3d8cdb7ca6f89627038f47a68aa578b9e675ddc937',
'transactionOutputIndex':30
},
{
'type':0,
'transactionId':'0x0220b5247654d05529f40b3d8cdb7ca6f89627038f47a68aa578b9e675ddc937',
'transactionOutputIndex':31
}
],
'inputsCommitment':'0xeefde614b74d871154856ad4a8a53214492ee8859a3faef4cafa92afe36f12c5',
'outputs':[
{
'type':4,
'amount':'50300',
'aliasId':'0xa5526c4a15558b709340822edf00cb348d8606a27e2e59b00432a0afe8afb74d',
'stateIndex':1,
'stateMetadata':'0x',
'foundryCounter':1,
'unlockConditions':[
{
'type':4,
'address':{
'type':0,
'pubKeyHash':'0x8297ac4149c80cca8225e5f2da36df89a93cd2998d7f6d488c97250a881e65af'
}
},
{
'type':5,
'address':{
'type':0,
'pubKeyHash':'0x8297ac4149c80cca8225e5f2da36df89a93cd2998d7f6d488c97250a881e65af'
}
}
]
},
{
'type':5,
'amount':'53200',
'serialNumber':1,
'tokenScheme':{
'type':0,
'mintedTokens':'0x3e8',
'meltedTokens':'0x0',
'maximumSupply':'0x3e8'
},
'unlockConditions':[
{
'type':6,
'address':{
'type':8,
'aliasId':'0xa5526c4a15558b709340822edf00cb348d8606a27e2e59b00432a0afe8afb74d'
}
}
],
'immutableFeatures':[
{
'type':2,
'data':'0xab'
}
]
},
{
'type':3,
'amount':'98600',
'nativeTokens':[
{
'id':'0x08a5526c4a15558b709340822edf00cb348d8606a27e2e59b00432a0afe8afb74d0100000000',
'amount':'0x3e8'
}
],
'unlockConditions':[
{
'type':0,
'address':{
'type':0,
'pubKeyHash':'0x8297ac4149c80cca8225e5f2da36df89a93cd2998d7f6d488c97250a881e65af'
}
}
]
}
]
},
'unlocks':[
{
'type':0,
'signature':{
'type':0,
'publicKey':'0xe62838fda7e8b77bf80e49967f0f089ae2a7230547d5231649732952f6336fae',
'signature':'0x47578dd3a390483d4de390f5f6ccc7af5838a9b0fb1ba0c519948c0d8638b4c0b86d0676f5fa616d5fdae53fec0fdacef72248a92ac388d8a20134528949380c'
}
},
{
'type':1,
'reference':0
},
{
'type':1,
'reference':0
},
{
'type':1,
'reference':0
}
]
},
'blockId':'0x50e0b55c5e618e3cb214a774c9574522e5b30118bebdef6cbb23c9cffeb2b347',
'inclusionState':'Pending',
'timestamp':'1665917714656',
'transactionId':'0x9d1e61384fc78777c8db475a3d6eaec6465c136dc3ce586ee46a9453aa3dfdc4',
'networkId':'1856588631910923207',
'incoming':False,
'note':None
}
}
{
"tokenId":"0x08429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef0800000000",
"transaction":{
"payload":{
"type":6,
"essence":{
"type":1,
"networkId":"1856588631910923207",
"inputs":[
{
"type":0,
"transactionId":"0x5cf6c0b12f8799cda57e0579a18fcba76722db9bb9b5d10e459489d391b1937a",
"transactionOutputIndex":0
},
{
"type":0,
"transactionId":"0x5cf6c0b12f8799cda57e0579a18fcba76722db9bb9b5d10e459489d391b1937a",
"transactionOutputIndex":2
}
],
"inputsCommitment":"0xd4f7b69a209e311e525e488c41a6b77ecc895f90ffdd1832ba31556f453fdd18",
"outputs":[
{
"type":4,
"amount":"50300",
"aliasId":"0x429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef",
"stateIndex":13,
"stateMetadata":"0x",
"foundriesCounter":0,
"unlockConditions":[
{
"type":4,
"address":{
"type":0,
"pubKeyHash":"0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
}
},
{
"type":5,
"address":{
"type":0,
"pubKeyHash":"0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
}
}
]
},
{
"type":5,
"amount":"52800",
"serialNumber":8,
"tokenScheme":{
"type":0,
"mintedTokens":"0x20",
"meltedTokens":"0x0",
"maximumSupply":"0x45"
},
"unlockConditions":[
{
"type":6,
"address":{
"type":8,
"aliasId":"0x429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef"
}
}
]
},
{
"type":3,
"amount":"2096320100",
"nativeTokens":[
{
"id":"0x08429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef0100000000",
"amount":"0x3233"
},
{
"id":"0x08429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef0200000000",
"amount":"0x3233"
},
{
"id":"0x08429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef0400000000",
"amount":"0x17"
},
{
"id":"0x08429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef0600000000",
"amount":"0x20"
},
{
"id":"0x08429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef0700000000",
"amount":"0x20"
},
{
"id":"0x08429fe5864378ce70699fc2d22bb144cb86a3c4833d136e3b95c5dadfd6ba0cef0800000000",
"amount":"0x20"
}
],
"unlockConditions":[
{
"type":0,
"address":{
"type":0,
"pubKeyHash":"0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
}
}
]
}
]
},
"unlocks":[
{
"type":0,
"signature":{
"type":0,
"publicKey":"0xde3152ce9d67415b9c5a042ea01caccc3f73ff1c0c77036874cb8badf9798d56",
"signature":"0x3c86bda5fd4e4f871a14920f7e630ec0cb8cbe7ccec03637441916b443a44c01ddc927459b6d20613025bd2a9e7f5afafd9cf1b2dbc979b128c6459de26da905"
}
},
{
"type":1,
"reference":0
}
]
},
"blockId":"0xccde79f09a527c755f8cc78132543e58e1a100b19efc2a2ab5acc6525cd660f2",
"inclusionState":"Pending",
"timestamp":"1664896472744",
"transactionId":"0xf323167737a556fcfcfa9da0248fc39aa344c275484a6f224769d2379ca49352",
"networkId":"1856588631910923207",
"incoming":false
}
}