I'm building a sort of ether exchange. Now suppose I have 2eth in my wallet, and I want to transfer all of it to any user. What value should I transfer from my 2 ethers such that gas can also be deducted from my account and my account becomes empty at the end of the transaction? What is the math? How do I calculate it?? If it is dependent upon the difficulty level of mining then how can my calculations co-op up with it?? Any help would be appreciated, thanks.
If you just want to do a plain ether transfer between accounts then it costs
21,000 gas. Approximately the average gas price is
21Gwei now in the network, so your transaction fee is around
0,00044 ETH. So, you should have cca.
2,00044 ETH on your account.
This could be useful for you to do the math taking into account the changes of the gasprice you can easily calculate here the transaction fee.