Unable to 'mint' a native asset directly to an address

I’ve been experimenting with some of the examples from the ‘sway-applications’ repo.

I am trying to understand better how to interact with native assets. Reading the code I can’t see any reason why I wouldn’t be able to mint a native to an arbitrary account. Yet when I try it fails.

I have tried this on both the native-asset project and the ‘NFT’ project.

To reproduce we can edit the tests as follows. For native-asset edit the first mint test:

#[test]
fn test_mint() {
    use std::context::balance_of;
    use std::constants::ZERO_B256;
    let src3_abi = abi(SRC3, CONTRACT_ID);
    let src20_abi = abi(SRC20, CONTRACT_ID);
-   let recipient = Identity::ContractId(ContractId::from(CONTRACT_ID));
+   let recipient = Identity::Address(Address::from(0x9876543210000000000000000000000000000000000000000000000000000000));
    let sub_id = ZERO_B256;
    let asset_id = AssetId::new(ContractId::from(CONTRACT_ID), sub_id);
    assert(balance_of(ContractId::from(CONTRACT_ID), asset_id) == 0);
}

And similarly for NFT:

#[test]
fn test_mint() {
    use std::context::balance_of;
    use std::constants::ZERO_B256;
    let src3_abi = abi(SRC3, CONTRACT_ID);
-   let recipient = Identity::Address(ContractId::from(CONTRACT_ID));
+   let recipient = Identity::Address(Address::from(0x1234560000000000000000000000000000000000000000000000000000000000));
    let sub_id = ZERO_B256;
    let asset_id = AssetId::new(ContractId::from(CONTRACT_ID), sub_id);
    assert(balance_of(ContractId::from(CONTRACT_ID), asset_id) == 0);
    src3_abi.mint(recipient, sub_id, 1);
    assert(balance_of(ContractId::from(CONTRACT_ID), asset_id) == 1);
}

Both of these tests fail when I change them to send the minted assets to an address.

I have read this answer: Can native assets be minted to arbitrary accounts? - #2 by david - but this situation is different - it is literally using the mint_to function internally that does a mint to the contract itself, and then a transfer out (this function: sway/sway-lib-std/src/asset.sw at 5e45116727707ddc9fdb85725aaf45443adc7ef5 · FuelLabs/sway · GitHub)

Is this a bug?

Hey @JasoonS the mint function is working as you described. To read more about the different token standards I defer you to this repository!

SRC-20 Rationale

SRC-3 Mint

Now the reason that the tests are failing is because of the assertions are in the test. The original test mints the token to the Contract but in your updated test they remain unchanged. The function used also ONLY looks at the balance of the contract id provided.

Thanks @calldelegation - the failure still happens even if I remove the ‘assert’ statements below the ‘mint’.

I’ll look into it more when I get a chance.

1 Like