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.
Web3 Pre-1.0 Stable Versions
Web3 1.0 Beta Version
1
// Initialize provider
2
import Fortmatic from 'fortmatic';
3
import Web3 from 'web3';
4
​
5
const fm = new Fortmatic('YOUR_API_KEY');
6
window.web3 = new Web3(fm.getProvider());
7
​
8
const toAddress = '0xb159752065EA68Ef0B22249Df25864E624fec45D';
9
const sendValue = web3.toWei(1, 'ether'); // Convert 1 ether to wei
10
11
// Get user account wallet address first
12
web3.eth.getAccounts((error, accounts) => {
13
if (error) throw error;
14
15
// Construct Ether transaction params
16
const txnParams = {
17
from: accounts[0],
18
to: toAddress,
19
value: sendValue
20
}
21
22
// Send Ether transaction with web3
23
web3.eth.sendTransaction(txnParams, (error, txnHash) => {
24
if (error) throw error;
25
console.log(txnHash);
26
});
27
});
Copied!
1
// Initialize provider
2
import Fortmatic from 'fortmatic';
3
import Web3 from 'web3';
4
​
5
const fm = new Fortmatic('YOUR_API_KEY');
6
window.web3 = new Web3(fm.getProvider());
7
​
8
const toAddress = '0xb159752065EA68Ef0B22249Df25864E624fec45D';
9
const sendValue = web3.utils.toWei(1, 'ether'); // Convert 1 ether to wei
10
11
// Get user account wallet address first
12
web3.eth.getAccounts().then((accounts) => {
13
​
14
// Construct Ether transaction params
15
const txnParams = {
16
from: accounts[0],
17
to: toAddress,
18
value: sendValue
19
}
20
21
// Send Ether transaction with web3
22
web3.eth.sendTransaction(txnParams)
23
.once('transactionHash', (hash) => { console.log(hash); })
24
.once('receipt', (receipt) => { console.log(receipt); });
25
});
Copied!

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!
1
const txnParams = {
2
from: accounts[0],
3
to: toAddress,
4
value: sendValue,
5
gasPrice: '0x2540be400', // Include your own gas price here.
6
}
Copied!
Last modified 2yr ago
Copy link