# How to get mock tokens to use in a test

**URL:** <https://forum.fuel.network/t/how-to-get-mock-tokens-to-use-in-a-test/53>\
**Category:** Rust SDK\
**Tags:** faqs\
**Created:** [November 14, 2022, 4:01pm UTC](https://forum.fuel.network/t/how-to-get-mock-tokens-to-use-in-a-test/53 "2022-11-14T16:01:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ControlCplusControlV](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/controlcpluscontrolv/32/999_2.png) [@ControlCplusControlV](https://forum.fuel.network/u/ControlCplusControlV)\
**Post date:** [November 14, 2022, 4:01pm UTC](https://forum.fuel.network/t/how-to-get-mock-tokens-to-use-in-a-test/53/1 "2022-11-14T16:01:40Z")

</div>

I was wondering how to get Mock Tokens to use when writing test contracts in Sway, akin to a mock ERC20 in Solidity. I considered deploying a small test contract like

```plaintext
impl MockToken for Contract {
    #[storage(read, write)]
    fn faucet(amount: u64) {
        let sender: Identity = msg_sender().unwrap();
        mint_to(amount, sender);
    }
}

```

but I was wondering if there was an easier way to do this from the SDK within the context of a test to give arbitrary tokens to a wallet

---

<div class="post-metadata">

**Author:** ![matt](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/matt/32/6_2.png) [@matt](https://forum.fuel.network/u/matt)\
**Post date:** [November 14, 2022, 8:27pm UTC](https://forum.fuel.network/t/how-to-get-mock-tokens-to-use-in-a-test/53/2 "2022-11-14T20:27:47Z")

</div>

Not super familiar with in-language testing, but this is how you do it in rust.  
[https://fuellabs.github.io/fuels-rs/v0.31.0/wallets/test-wallets.html](https://fuellabs.github.io/fuels-rs/v0.31.0/wallets/test-wallets.html)

---

<div class="post-metadata">

**Author:** ![kern](https://avatars.discourse-cdn.com/v4/letter/k/90ced4/32.png) [@kern](https://forum.fuel.network/u/kern)\
**Post date:** [November 14, 2022, 8:40pm UTC](https://forum.fuel.network/t/how-to-get-mock-tokens-to-use-in-a-test/53/3 "2022-11-14T20:40:18Z")

</div>

Here’s an example of how you can do it from the SDK (it assumes that you have a wallet file persisted to disk; alternatively, you can generate a random wallet using the SDK):

```auto
use fuels::{
    prelude::{
        setup_single_asset_coins, setup_test_client, AssetId, Config, Contract, Provider,
        TxParameters, WalletUnlocked, DEFAULT_COIN_AMOUNT,
    },
    signers::Signer,
};
use fuels_core::parameters::StorageConfiguration;

async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let wallet_path_str = wallet_path.as_os_str().to_str().unwrap();

    let mut wallet =
        WalletUnlocked::load_keystore(wallet_path_str, [WALLET_PASSWORD], None)
            .unwrap();

    let bin_path_str = [CONTRACT_BIN_PATH];
    let _compiled = Contract::load_contract(bin_path_str, &None).unwrap();

    let number_of_coins = 10;
    let asset_id = AssetId::zeroed();
    let coins = setup_single_asset_coins(
        wallet.address(),
        asset_id,
        number_of_coins,
        DEFAULT_COIN_AMOUNT,
    );

    let config = Config {
        utxo_validation: false,
        addr: [FUEL_NODE_ADDR],
        ..Config::local_node()
    };

    let (client, _) = setup_test_client(coins, vec![], Some(config), None, None).await;

    let provider = Provider::new(client);

    wallet.set_provider(provider.clone());

    let contract_id = Contract::deploy(
        bin_path_str,
        &wallet,
        TxParameters::default(),
        StorageConfiguration::default(),
    )
    .await
    .unwrap();

    Ok(())
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/fuel/original/2X/5/57d5a345cc15a64b636e0d56e042857f8a0e80b1.png) [@system](https://forum.fuel.network/u/system)\
**Post date:** [February 20, 2023, 7:05am UTC](https://forum.fuel.network/t/how-to-get-mock-tokens-to-use-in-a-test/53/4 "2023-02-20T07:05:48Z")

</div>

Closed on February 20, 2023, 7:05am UTC

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
