Fuelet | Wallet on Fuel
  • Introduction
  • Intergration guide
    • Intro
    • Detecting wallet presence
    • Selecting Fuelet as a connector
    • Best practice
    • Audit and Security Assurance
  • Wallet API
    • Intro
    • Connecting
    • Getting current account
    • Getting current network
    • Signing messages
    • Sending transactions
    • Events
  • Resources
    • Media Kit
Powered by GitBook
On this page
  1. Wallet API

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]]);

transactionRequest.addResources(resources);
const response = await wallet.sendTransaction(transactionRequest);

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

Last updated 1 year ago