[Ethereum] How to transfer the whole balance of an account

accountsbalancesfeestransactions

If I have an account with 5 ETH, can I send the full account balance of 5ETH to another account and have exactly 5ETH received on the second account ?

I understood that it will fail because I have no ether left to pay for the transaction fees.

If I want exactly 5 ETH to be received by the second account, I think I should have around 5,0002 ETH in my account to be able to transfer 5 ETH. Can you confirm?

Best Answer

No.

You cannot send the entire balance because the fees are deducted from your account's balance, not from the value being sent. To sweep an account you need to send balance-gas*price ETH as the value, and also manually set the gas and gasPrice to ensure that you exactly zero your account.

E.g. If you have 5ETH and want to sweep it:

  • A plain account-to-account transaction costs 21000 gas
  • The current minimum gas price in the network is 20 GWei
  • Set value to 5ETH - 21000*20GWei = 5ETH - 42K GWei = 4.999958ETH
Related Topic