1

I'm trying to send all of my ETH balance to another address. I try to do this the following way, but always receive an error:

[~] $ geth attach ipc:~/.ethereum/geth.ipc
WARN [06-21|15:26:14.974] Enabling deprecated personal namespace
Welcome to the Geth JavaScript console!

instance: Geth/v1.14.5-stable-0dd173a7/linux-amd64/go1.22.4
at block: 20140386 (Fri Jun 21 2024 15:26:11 GMT+0200 (CEST))
 datadir: /home/svandijk/.ethereum
 modules: admin:1.0 debug:1.0 engine:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

To exit, press ctrl-d or type exit
>txh = eth.sendTransaction({from: eth.accounts[0], to: [targetadd, not sure if this is sensitive info], value: eth.getBalance(eth.accounts[0]).sub(web3.eth.gasPrice.mul(21000))});
Error: gas required exceeds allowance (10501)
        at web3.js:6387:9(39)
        at send (web3.js:5116:62(29))
        at <eval>:1:26(27)

The idea being to send (balance - gasprice * 21000), leaving enough to cover the transaction fees. I'm not sure what the error means, what is the 'allowance'? And what is the number between the brackets (10501)?

I thought maybe I was making a mistake in calculating the amount I can transfer, and subtracted more (to have more left over for higher transaction fees). But even when subtracting (gasprice * 31000), I get the same error (and a higher number between the brackets).

In case it wasn't obvious, I'm a total noob in Ethereum and crypto in general, so I apologize if I'm asking something stupid. Thanks!

1 Answer 1

1

I'm still not exactly sure what the error is trying to convey precisely, but I solved this by:

  • not using eth.gasPrice as the gasprice (instead increasing it a little)
  • explicitly passing gas and gasprice to the sendTransaction command.

So:

#check the gasprice
> eth.gasPrice;
[some_value]
> var my_gas_price = [some_slightly_higher_value];
> var tx_fee = my_gas_price.mul(21000);
> txh = eth.sendTransaction({from: eth.accounts[0], to: [targetadd], value: eth.getBalance(eth.accounts[0]).sub(tx_fee), gas: 21000, gasprice: my_gas_price});

This time the transaction went through immediately, but I'm unsure if it was because of increasing the gasprice or adding it explicitly to the command, or both.

After this transaction the account was left with a balance of exactly 0.0 ETH.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.