Can native assets be minted to arbitrary accounts?

I’ve read the SRC-20 token standard and the spec of the MINT instruction, but it is not clear whether assets can be minted to arbitrary accounts?

By the looks of it, assets have to be minted to the current contract first, and only then can be transferred. Is my understanding correct?

1 Like

This is correct, assets are minted directly to the contract, then can be transferred out.

But that’s effectively the same thing… is there any use case where this doesn’t work for you?

1 Like

Well, not strictly the same thing. If the MINT opcode accepted a to parameter, the contract could mint assets to third-party accounts directly.

Anyway, this is a smol technical detail, which only nerds like us need care about.

Nope

1 Like

One reason behind this decision, is that there’s actually two opcodes for transferring assets in the FuelVM: TR transfers tokens to a contract (increasing the contract’s balance), and TRO transfers tokens to an address by adding the assets to an output UTXO.

If MINT directly had a “to” address, there would need to be two opcodes (MINT & MINTO). So it’s simpler to just mint directly to the minting contract.

1 Like

I’ve just stumbled upon the Native Token Example in the Sway docs, which implements the following functions:

impl NativeAssetToken for Contract {
    /// <---- snip  ----> ///

    /// Mint and send this contracts native token to a destination contract.
    fn mint_and_send_to_contract(amount: u64, destination: ContractId) {
        mint_to_contract(destination, ZERO_B256, amount);
    }

    /// Mind and send this contracts native token to a destination address.
    fn mint_and_send_to_address(amount: u64, recipient: Address) {
        mint_to_address(recipient, ZERO_B256, amount);
    }
}

This in turn has led me to the mint_to_contract function in the Sway Standard Library.

Thus, it seems to me that the problem of “how to mint and transfer in one go” is effectively solved at a level above the raw FuelVM, i.e., in the Sway Standard Library.

1 Like