Skip to content

Transferring assets

Consider a scenario where you're interacting with a smart contract and need to transfer assets to a recipient's wallet. The addTransfer enables you to combine these actions into a single transaction seamlessly.

The addTransfer method allows you to append an asset transfer to your contract call transaction. You can use it is shown in the following example:

ts
const recipient = Wallet.generate({ provider });

await contract.functions.echo_u64(100).addTransfer(recipient.address, 100, BaseAssetId).call();
See code in context

In the previous example, we first use a contract call to the echo_u64 function. Following this, addTransfer is added to chain call to include a transfer of 100 units of the BaseAssetId in the transaction.

Multiple Transfers

You can chain multiple addTransfer calls to include various transfers in a single transaction. Here's how you can concatenate these calls:

ts
const recipient1 = Wallet.generate({ provider });
const recipient2 = Wallet.generate({ provider });

await contract.functions
  .echo_u64(100)
  .addTransfer(recipient1.address, 100, BaseAssetId)
  .addTransfer(recipient1.address, 400, ASSET_A)
  .addTransfer(recipient2.address, 300, ASSET_B)
  .call();
See code in context