Function std::asset::transfer

pub fn transfer(to: Identity, asset_id: AssetId, amount: u64) 
Expand description

Transfer amount coins of the type asset_id and send them
to to by calling either force_transfer_to_contract or
transfer_to_address, depending on the type of Identity.

Additional Information

If the to Identity is a contract this may transfer coins to the contract even with no way to retrieve them
(i.e. no withdrawal functionality on receiving contract), possibly leading
to the PERMANENT LOSS OF COINS if not used with care.


  • to: [Identity] - The recipient identity.
  • asset_id: [AssetId] - The asset to transfer.
  • amount: [u64] - The amount of coins to transfer.


  • When amount is greater than the contract balance for asset_id.
  • When amount is equal to zero.
  • When there are no free variable outputs when transferring to an Address.


use std::{constants::ZERO_B256, asset::transfer};

fn foo() {
    let to_address = Identity::Address(Address::from(ZERO_B256));
    let to_contract_id = Identity::ContractId(ContractId::from(ZERO_B256));
    transfer(to_address, AssetId::base(), 500);
    transfer(to_contract_id, AssetId::base(), 500);