Sending transactions

You can request a user to sign and send a transaction on behalf of the connected account.

For that, you'll need to obtain an instance of the wallet object, construct the transaction you want to send and call the sendTransaction function on it.

const accounts = await fuel.accounts();
const account = accounts[0];

const transactionRequest = new ScriptTransactionRequest({
  gasLimit: 50_000,
  gasPrice: 1,

const toAddress = Address.fromString(toAccount);
const amount = bn.parseUnits("0.1");
transactionRequest.addCoinOutput(toAddress, amount);

const wallet = await fuel.getWallet(account);
const resources = await wallet.getResourcesToSpend([[amount, NativeAssetId]]);

const response = await wallet.sendTransaction(transactionRequest);

// wait for transaction to be completed
await response.wait();

Last updated