Send Ether Transaction

If you have replaced your web3 provider with Fortmatic provider, nothing needs to be changed for web3 send Ether transactions to continue working.

The Fortmatic X modal will pop open and ask users to confirm their transaction once this web3 function is called on the client-side.

// Initialize provider
import Fortmatic from 'fortmatic';
import Web3 from 'web3';

const fm = new Fortmatic('YOUR_API_KEY');
window.web3 = new Web3(fm.getProvider());

const toAddress = '0xb159752065EA68Ef0B22249Df25864E624fec45D';
const sendValue = web3.toWei(1, 'ether'); // Convert 1 ether to wei
  
// Get user account wallet address first
web3.eth.getAccounts((error, accounts) => {
  if (error) throw error;
  
  // Construct Ether transaction params
  const txnParams = {
    from: accounts[0],
    to: toAddress,
    value: sendValue
  }
  
  // Send Ether transaction with web3
  web3.eth.sendTransaction(txnParams, (error, txnHash) => {
    if (error) throw error;
    console.log(txnHash);
  });
});

Custom Gas Price

Fortmatic provides the option to offer a customized gas price. If provided, it will be shown as a suggested option in the delivery fee section. One parameter addition to include a customized gas price should suffice. Gas limit is optional, if not provided, Fortmatic will smartly estimate the gas limit for the transaction!

const txnParams = {
  from: accounts[0],
  to: toAddress,
  value: sendValue,
  gasPrice: '0x2540be400', // Include your own gas price here.
}

Last updated