I'm struggling with transferring 1 ETH to an address using Geth console. I used all sorts of codes and examples I found online, but it all returns "insufficient funds for transfer" or some other errors.
I have 1 ETH and some in this wallet. Is there a function of some sort where it can calculate required gas price, pay the bare minimum and transfer ALL my funds as much as possible (after deducting the gas price)?
Example function I used that didn't work:
var transferAll = function(from, to) {
var gas = '30000';
var gasPrice = eth.gasPrice;
var gasTotal = gasPrice.mul(gas);
var totalValue = eth.getBalance(from).sub(gasTotal)-1;
console.log("Transfer :"+totalValue+", from "+from+" to "+to);
personal.unlockAccount(from);
var result = eth.sendTransaction({from: from, to: to, value: totalValue});
console.log("Transaction hash:", result);
};
I'm getting 2 errors
- "gas required exceeds allowance (0)"
- " insufficient funds for transfer"
no matter what I do I can't satisfy the requirements and initiate a transaction
eth.sendTransaction({from: '..', to: '..', value: .., gas: gas, gasPrice: gasPrice})
. If recipient is an EOA use gas = 21000, if it is a contract it is better to use estimateGas.