I often find myself having to figure out the exact amount of Ether I can send from one address, while still accounting for the transaction fee. More often than not, I have a few tidbits left over, which I then have to abandon, since they are worth less than the fee itself.
Does anyone know the syntax for a command that would send all the remaining Ether, taking the fee into account?
Thanks!
0 ·
Comments
amount - (gasPrice * 21000)
You can test for yourself here.
I guess I'll have to figure out how to obtain the balance and gas price programatically, and I should be able to cook up some nice "send all" formula that will work every time.
https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethgasprice
https://www.reddit.com/r/ethereum/comments/3h54ta/5_eth_bounty_for_sweeping_balance_command/
> eth.getBalance(eth.accounts[0])
81363063346050281000
> eth.gasPrice*21000
1050000000000000
> eth.getBalance(eth.accounts[0])-eth.gasPrice*21000
81362013346050250000
And on another account I see that the result is rounded up.
What happens when you are a few Ada short of the needed txfee?
I wonder what it would take to replace the math engine inside the geth/eth client to handle extra-high-precision calculations...