Hello everyone, I start learning programming, sorry for my mistakes.
I need to send all balance (100 ether) from account 1 to the account 2. But he does not have enough money for the transfer. I understand that I first need to get the balance of account 1, get the gas and price of gas, fold this and move this to the "value:" But I do not quite understand how to do it right.
const privKey = ' ';
const addressFrom = ' ';
const addressTo = ' ';
const web3 = new Web3('http://127.0.0.1:7545');
var balance = web3.eth.getBalance(addressFrom);
// Transaction
const deploy = async () => {
console.log(
'Transaction from: ' + addressFrom, 'to: ' + addressTo
);
const createTransaction = await web3.eth.accounts.signTransaction(
{
from: addressFrom,
to: addressTo,
value: web3.utils.toWei('100','ether'),
gas: '21000',
}, privKey);