0

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

  1. "gas required exceeds allowance (0)"
  2. " insufficient funds for transfer"

no matter what I do I can't satisfy the requirements and initiate a transaction

2
  • You are missing gas and gasPrice with sendTransaction, something like this 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.
    – Ismael
    Commented Apr 27, 2021 at 5:36
  • Can you please give me a function like transferAll or one liner that will calculate gasPrice and gas automatically and send ALL my balance to new account? @Ismael
    – Mark G
    Commented Apr 27, 2021 at 5:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.