If you need multiple test wallets, they can be set up using the launch_custom_provider_and_get_wallets method.
use fuels::prelude::*;// This helper will launch a local node and provide 10 test wallets linked to it.// The initial balance defaults to 1 coin per wallet with an amount of 1_000_000_000let wallets =launch_custom_provider_and_get_wallets(WalletsConfig::default(), None, None).await?;
You can customize your test wallets via WalletsConfig.
let num_wallets =5;let coins_per_wallet =3;let amount_per_coin =100;let config =WalletsConfig::new(Some(num_wallets),Some(coins_per_wallet),Some(amount_per_coin),);// Launches a local node and provides test wallets as specified by the configlet wallets =launch_custom_provider_and_get_wallets(config, None, None).await?;
Icon InfoCircle
Note Wallets generated with launch_provider_and_get_wallet or launch_custom_provider_and_get_wallets
will have deterministic addresses.
You can create a test wallet containing multiple assets (including the base asset to pay for gas).
use fuels::prelude::*;letmut wallet =WalletUnlocked::new_random(None);let num_assets =5; // 5 different assetslet coins_per_asset =10; // Per asset id, 10 coins in the walletlet amount_per_coin =15; // For each coin (UTXO) of the asset, amount of 15let (coins, asset_ids) =setup_multiple_assets_coins( wallet.address(), num_assets, coins_per_asset, amount_per_coin,);let provider =setup_test_provider(coins.clone(), vec![], None, None).await?;wallet.set_provider(provider);
coins: Vec<(UtxoId, Coin)> has num_assets * coins_per_assets coins (UTXOs)
asset_ids: Vec<AssetId> contains the num_assets randomly generated AssetIds (always includes the base asset)
The Fuel blockchain holds many different assets; you can create your asset with its unique AssetId or create random assets for testing purposes.
You can use only one asset to pay for transaction fees and gas: the base asset, whose AssetId is 0x000...0, a 32-byte zeroed value.
For testing purposes, you can configure coins and amounts for assets. You can use setup_multiple_assets_coins:
use fuels::prelude::*;letmut wallet =WalletUnlocked::new_random(None);let num_assets =5; // 5 different assetslet coins_per_asset =10; // Per asset id, 10 coins in the walletlet amount_per_coin =15; // For each coin (UTXO) of the asset, amount of 15let (coins, asset_ids) =setup_multiple_assets_coins( wallet.address(), num_assets, coins_per_asset, amount_per_coin,);
Icon InfoCircle
Note If setting up multiple assets, one of these assets will always be the base asset.
If you want to create coins only with the base asset, then you can use:
let wallet =WalletUnlocked::new_random(None);// How many coins in our wallet.let number_of_coins =1;// The amount/value in each coin in our wallet.let amount_per_coin =3;let coins =setup_single_asset_coins( wallet.address(),BASE_ASSET_ID, number_of_coins, amount_per_coin,);
Icon InfoCircle
Note Choosing a large number of coins and assets for setup_multiple_assets_coins or setup_single_asset_coins can lead to considerable runtime for these methods. This will be improved in the future but for now, we recommend using up to 1_000_000 coins, or 1000 coins and assets simultaneously.