Complete the code to send a transaction using the web3 library.
const tx = {
from: senderAddress,
to: receiverAddress,
value: web3.utils.toWei('1', '[1]')
};The value must be converted to wei from ether using web3.utils.toWei with 'ether' as the unit.
Complete the code to sign the transaction with the private key.
const signedTx = await web3.eth.accounts.signTransaction(tx, [1]);The transaction must be signed with the sender's private key to authorize it.
Fix the error in sending the signed transaction.
web3.eth.sendSignedTransaction([1].rawTransaction) .on('receipt', console.log);
The signed transaction object is signedTx, which contains the rawTransaction property.
Fill both blanks to create a transaction object with gas and gasPrice.
const tx = {
from: senderAddress,
to: receiverAddress,
value: web3.utils.toWei('0.5', 'ether'),
gas: [1],
gasPrice: web3.utils.toWei('[2]', 'gwei')
};The standard gas limit for a simple ETH transfer is 21000, and a common gas price is 50 gwei.
Fill all three blanks to create a transaction receipt handler.
web3.eth.sendSignedTransaction(signedTx.rawTransaction) .on('[1]', (receipt) => { console.log('Transaction [2] with hash:', receipt.[3]); });
The event to listen for is 'receipt', the message says 'confirmation', and the receipt object has the 'transactionHash' property.