10

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?

  • I edited your question to make both answer able to answer the same way as both were saying the same thing but one started by no and the other by yes 🤔 – Nicolas Massart Jun 7 '16 at 15:43
11

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
  • 3
    I always wondered why there wasn't a built-in function in the client to calculate that amount ;) Sure it's simple enough, but for beginners it's like difficult as it involves calculating things with new unknown quantities ! – euri10 Jun 7 '16 at 15:32
  • @euri10 and with unit multiplier differences. I still can't figure how to calculate fee in ether from Wei gas price... I agree, should be done in the wallet. – Nicolas Massart Jun 7 '16 at 15:46
  • 1
    20 Gwei is not the minimum gas price. It's the default gas price. You can sent transactions with a gas price lower than 20 Gwei. – Paweł Bylica Jun 7 '16 at 21:18
  • It is the minimum allowed by Geth by default. Even though it is allowed to set it lower than that, other nodes in the network will not accept and hence will not forward your transaction to miners. So even if a miner were to accept lower fees, you'd not be able to get it to them currently. This is done to avoid network spam until a proper dynamic solution can be figured out (note, it's a yet unsolved problem for bitcoin too). – Péter Szilágyi Jun 8 '16 at 9:00
  • 2
    21k times 20 isn't 42k, it's 420k. I think you've missed a zero in your answer, and the value needs to be 4.99958 instead of 4.999958. Doesn't it? – Chris Moore Jul 23 '16 at 4:09
5

Basic answer is no !

Anytime you want to perform a transaction, you'll have to pay a fee for the computation involved in validating and mining your tx. If you do not have enough gas, you cannot send your tx to the network. In your example, send "all" and the receiver will get 5 minus fees.

0

My suggestion would be to automate it.

First, set the account and unlock it after launching geth attach:

var accountNum = 0
personal.unlockAccount(eth.accounts[accountNum]);

Now

var amount_to_send_eth = web3.fromWei(eth.getBalance(eth.accounts[accountNum]), "ether");
var amount_to_send_wei = amount_to_send_eth *1000000000000000000
var transactionFee = web3.eth.gasPrice * 21001;
var total_amount_to_send_wei = transactionFee + amount_to_send_wei 
eth.sendTransaction({from:eth.accounts[accountNum], to:"0xD3ADB33FD3ADB33FD3ADB33F", value: total_amount_to_send_wei });

After that, a TXID is returned, that can be used to check if the transaction completed.

I'm a beginner, so hints how to imrpove it further are appreciated!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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