Skip to main content

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:

  1. Create an account manager.
  2. Get Alice's which was created in the first guide.
  3. Create the NativeTokenOptions.
  4. Mint the native token by calling the Account.mint_native_token(native_token_options, options) function.
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

Expected Output

Transaction: 0xaa9737fb4007e8b0f4c181d6923b0e3547ae178c23c25233985bb22f61c84de7 
Block sent: http://localhost:14265/api/core/v2/blocks/0x807dbdde107008dcc9acae29a0e32c261590bef13e5f5d8d3bb60949e633abd8