6

Two situations.

  1. You want to transfer all the money in an account and want to compute the right amount of gas and tax suc that you transfer all that is possible and leave the account with 0.

  2. You want to transfer a specific amount of money and want to compute the right amount of gas and tax such that you transfer exactly the desired amount.

How do you compute both values?

MaiaVictor
  • 3,177
  • 2
  • 17
  • 37
  • Related: http://ethereum.stackexchange.com/questions/5759/how-to-transfer-the-whole-balance-of-an-account – eth Jul 29 '16 at 01:32

2 Answers2

4

The second is simpler, the gas fees are deducted from your account, not from the transferred value, so you need only to specify 21K gas (transaction cost) * 50 shannon (minimum gas price currently).

To sweep your account, you need to calculate the transaction cost (21K gas * 50 shannon), and send your total balance - costs. That will leave your account at 0 balance.

Péter Szilágyi
  • 10,436
  • 39
  • 42
  • 1
    Currently, it appears that in geth there is a bug that does not allow reducing the balance to 0, you need to leave 1 Wei. – Tjaden Hess Feb 04 '16 at 16:56
  • Actually, it's a rounding error in the JS console. See https://github.com/ethereum/go-ethereum/issues/2173#issuecomment-184297935 – Tjaden Hess Feb 16 '16 at 00:31
4

As discussed by Tjaden Hess here you need to multiply gas amount with gas price and substract a single wei on top of that (not sure why).

You can specify the amount of 21,000 gas and the gas price of 50 shannon:

{from:'0xACCOUNT', to:'0xRECIPIENT', value:eth.getBalance('0xACCOUNT') - 21000 * 50000000000 - 1, gas:21000, gasPrice:50000000000}

Note, that in the mist ethereum wallet, you have issues with rounding of all the decimals. Using a command line interface like geth is recommended to figure out the exact amounts.


The gas price is a moving target. If this is not working you could also use the transaction cost calculator for Ethereum.

q9f
  • 32,913
  • 47
  • 156
  • 395
  • 1
    Neither of you told me how do I find those numbers (21000 and 50). I've just attempted that, but the transfer isn't going... – MaiaVictor Feb 04 '16 at 17:12
  • 1
    From Ethereum Yellow Paper, 21000 is Gtransaction in Appendix G. Gas price of 50 shannon is asked at http://ethereum.stackexchange.com/q/324/42. – eth Feb 04 '16 at 18:24