Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Transfer ENTIRE balance from one Ethereum account to another
* Transfer the ENTIRE BALANCE from one account to another.
* Before you call this, you must unlock your account:
* personal.unlockAccount(from)
* @see
* @see
function transferEntireBalance(from, to) {
var gas = new BigNumber(21000);
var price = web3.eth.gasPrice; // current average price; or set your own
var balance = eth.getBalance(from);
var value = balance.minus(gas.times(price));
if (value.greaterThan(0)) {
var txn = eth.sendTransaction({from: from, to: to, gasPrice: price, gas: gas, value: value});
console.log(" Transfer", from, "to", to, ":", txn);
return txn;
console.log(" Transfer "+ from +" to "+ to +": (No funds available)");
return null;
Copy link

willowTank commented Aug 7, 2018

hello ross. How are you?
-- var gas = new BigNumber(21000);
What do you mean by 21000?
I am a beginner of ethereum.
Can you guide me for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment