This guide details the process of checking account balances and executing Ether (ETH) transfers using Go Ethereum's JavaScript console. It follows from a previous setup where accounts were created and mining was initiated, providing a hands-on approach to managing a local blockchain.
Checking Your Account Balance
After creating accounts and starting the mining process, the first step is to verify your account's ETH balance. In the Go Ethereum console, you can check the balance of your primary account using the eth.getBalance function.
> eth.getBalance(eth.accounts[0])
80000000000000000000The returned value is in Wei, the smallest denomination of ETH, where 1 ETH equals 1e18 Wei (or 1,000,000,000,000,000,000 Wei). To convert this value into a more readable Ether amount, use the web3.fromWei() function.
Converting Wei to Ether
The web3.fromWei() function converts values from Wei to other Ethereum denominations. The first argument is the value in Wei, and the second is the target unit (e.g., "ether," "kwei," or "tether").
Example conversions:
> web3.fromWei(1e18, "ether")
"1"
> web3.fromWei(1e3, "kwei")
"1"
> web3.fromWei(1e30, "tether")
"1"To check your account balance in ETH:
> web3.fromWei(eth.getBalance(eth.accounts[0]), "ether")
80This confirms a balance of 80 ETH in the account.
Executing an ETH Transfer
To send ETH between accounts, you’ll use the eth.sendTransaction() function. First, ensure you have at least two accounts:
> eth.accounts
["0xae9abfc6eca2b25d579be8649d4f232f80d3bd46", "0x46c001f57b55abbe9086d595e15cbf7dc3a9b5b2"]Unlocking Your Account
Before sending a transaction, you must unlock the sender’s account using personal.unlockAccount(). This requires the passphrase set during account creation.
> personal.unlockAccount(eth.accounts[0])
Unlock account 0xae9abfc6eca2b25d579be8649d4f232f80d3bd46
Passphrase:
trueSending the Transaction
With the account unlocked, initiate the transfer:
> eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], value: web3.toWei(10, "ether")})
"0x29a48a49a140c0774b6876d343dda6df4af71b00bd515e22f6c9c08d1f4a7a00"The returned hexadecimal string is the transaction hash, a unique identifier for your transfer.
Transaction Confirmation and Mining
After sending the transaction, it must be included in a block to be confirmed. If mining is stopped, the transaction remains pending.
Check the transaction status with eth.getTransaction():
> eth.getTransaction("0x29a48a49a140c0774b6876d343dda6df4af71b00bd515e22f6c9c08d1f4a7a00")
{
blockHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
blockNumber: null,
...
}A blockNumber of null indicates the transaction is not yet confirmed.
Restarting Mining
Start mining to include the transaction in a block:
> miner.start(1)
nullOnce mining begins, check the transaction again:
> eth.getTransaction("0x29a48a49a140c0774b6876d343dda6df4af71b00bd515e22f6c9c08d1f4a7a00")
{
blockHash: "0x74dfcccd8a18dd661b449d5802bac83113356f7cd8dd598b0d0de191293f79c6",
blockNumber: 17,
...
}The blockNumber now shows 17, indicating confirmation.
Stop mining after the transaction is processed:
> miner.stop()
nullVerifying Balances
After confirmation, check the recipient’s balance:
> web3.fromWei(eth.getBalance(eth.accounts[1]), "ether")
10The sender’s balance may also change due to mining rewards:
> web3.fromWei(eth.getBalance(eth.accounts[0]), "ether")
85The increase is from block rewards earned during mining.
Reviewing Transaction Details
Use eth.getTransactionReceipt() to review gas usage and other transaction details:
> eth.getTransactionReceipt("0x29a48a49a140c0774b6876d343dda6df4af71b00bd515e22f6c9c08d1f4a7a00")
{
blockHash: "0x74dfcccd8a18dd661b449d5802bac83113356f7cd8dd598b0d0de191293f79c6",
blockNumber: 17,
gasUsed: 21000,
...
}The gasUsed field shows the actual gas consumed by the transaction.
👉 Explore more strategies for managing blockchain transactions
Frequently Asked Questions
What is the difference between Wei and Ether?
Wei is the smallest unit of Ether, similar to cents to a dollar. 1 Ether equals 1e18 Wei. Conversions are necessary because blockchain transactions often use Wei for precision.
Why do I need to unlock my account before sending ETH?
Unlocking your account with the passphrase proves you own the private key, ensuring security. Without this step, transactions cannot be signed and broadcasted.
What does a transaction hash represent?
A transaction hash is a unique identifier generated for each transaction. It allows you to track the transaction’s status on the blockchain.
Why did my balance increase after sending ETH?
If you were mining during the transaction, your balance likely increased due to block rewards. Mining adds new blocks to the blockchain, rewarding the miner with ETH.
How can I check if a transaction is confirmed?
Use eth.getTransaction() and check the blockNumber field. If it is null, the transaction is pending. A non-null value indicates confirmation.
What is gas used in Ethereum transactions?
Gas is the fee required to execute operations on the Ethereum network. Each transaction consumes gas, which is paid in ETH. The gasUsed field in the receipt shows the total gas consumed.