Skip to content

Wallet Transferring

This guide demonstrates how to transfer assets between accounts and contracts, and how to validate your balance prior to a transfer.

Transferring Between Wallets

Transferring assets between wallets is really simple within the SDK.

ts
const myWallet = Wallet.fromPrivateKey(privateKey, provider);

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

const txResponse = await myWallet.transfer(recipient.address, 100, assetId);

await txResponse.waitForResult();
See code in context

After waiting the transaction to be processed, the assets are successfully moved to the recipient's wallet.

It is also possible to specify the recipient's address as a string:

ts
const myWallet = Wallet.fromPrivateKey(privateKey, provider);

const address = 'fuel1zc7r2rwuzl3uskfc0w737780uqd8sn6lfm3wgqf9wa767gs3sems5d6kxj';

const txResponse = await myWallet.transfer(address, 100, assetId);
See code in context

When transferring the base chain coin like ETH, you can omit the assetId:

ts
const myWallet = Wallet.fromPrivateKey(privateKey, provider);

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

const txResponse = await myWallet.transfer(recipient.address, 100);
See code in context

Transferring To Contracts

Transferring assets from your wallet to a deployed contract is straightforward. All you need is the contract's address.

You can transfer assets to a deployed contract instance by using its id:

ts
const myWallet = Wallet.fromPrivateKey(privateKey, provider);

const txResponse = await myWallet.transferToContract(contract.id, 100, assetId);

await txResponse.waitForResult();
See code in context

Alternatively, you can simply use the contract's string address in the Bech32 format:

ts
const myWallet = Wallet.fromPrivateKey(privateKey, provider);

const contractAddress = contract.id.toString();

const txResponse = await myWallet.transferToContract(contractAddress, 100, assetId);

await txResponse.waitForResult();
See code in context

Balances

Before transferring assets, ensure your wallet has sufficient funds. Attempting a transfer without enough funds will result in an error: not enough coins to fit the target.

You can see how to check your balance at the checking-balances page.