Exploring Go Ethereum (Part 3): Sending Transactions

ยท

In our previous session, we created an Ethereum account and performed mining. Now, let's start by checking the account balance.

Checking Your Account Balance

First, let's verify the account status. After mining in the last session, the balance of the coinbase address we configured has increased.

> eth.getBalance(eth.accounts[0])
80000000000000000000

Note that the unit here is Wei, not ETH. If you've used Ethereum before, you might recognize this unit from transaction details.

Understanding Wei and Ether Conversions

> web3.fromWei(1e18, "ether")
"1"
> web3.fromWei(1e3, "kwei")
"1"
> web3.fromWei(1e30, "tether")
"1"
> web3.toWei(1, "kwei")
"1000"

Now, let's check the balance in Ether:

> web3.fromWei(eth.getBalance(eth.accounts[0]), "ether")
80

Success! Our balance is 80 ETH.

Sending a Transaction

Now that we've confirmed our balance, let's send a transaction. Currently, we have two accounts:

> eth.accounts
["0xae9abfc6eca2b25d579be8649d4f232f80d3bd46", "0x46c001f57b55abbe9086d595e15cbf7dc3a9b5b2"]

We'll send 10 ETH from the first account to the second using eth.sendTransaction(). Specify:

Unlocking the Account

Before sending, unlock the account using personal.unlockAccount():

> personal.unlockAccount(eth.accounts[0])
Unlock account 0xae9abfc6eca2b25d579be8649d4f232f80d3bd46
Passphrase:
true

Now, execute the transaction:

> eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], value: web3.toWei(10, "ether")})
"0x29a48a49a140c0774b6876d343dda6df4af71b00bd515e22f6c9c08d1f4a7a00"

The returned hash confirms the transaction was submitted. However, the balance hasn't changed yet because the transaction needs to be mined.

Mining the Transaction

Since mining was stopped earlier, restart it to confirm the transaction:

> miner.start(1)
null
> eth.mining
true

Check the transaction status:

> eth.getTransaction("0x29a48a49a140c0774b6876d343dda6df4af71b00bd515e22f6c9c08d1f4a7a00")
{
  blockNumber: 17,
  // ... (other details)
}

After mining, stop the miner:

> miner.stop()
null
> eth.mining
false

Verifying Balances

Check the recipient's balance:

> eth.getBalance(eth.accounts[1])
10000000000000000000
> web3.fromWei(eth.getBalance(eth.accounts[1]), "ether")
10

The sender's balance now reflects mining rewards:

> web3.fromWei(eth.getBalance(eth.accounts[0]), "ether")
85

Transaction Receipt

For detailed gas usage, use eth.getTransactionReceipt():

> eth.getTransactionReceipt("0x29a48a49a140c0774b6876d343dda6df4af71b00bd515e22f6c9c08d1f4a7a00")
{
  gasUsed: 21000,
  // ... (other details)
}

FAQ

1. Why is my balance still in Wei?

Ethereum defaults to Wei for precision. Use web3.fromWei() to convert to ETH.

2. How do I unlock my account?

Run personal.unlockAccount(address) and enter your passphrase.

3. Why hasn't my transaction gone through?

Transactions require mining. Start mining with miner.start().

4. What is gasUsed in the receipt?

It shows the computational effort (in gas) required for the transaction.

5. Can I send fractions of ETH?

Yes! Specify the value in Wei (e.g., web3.toWei(0.1, "ether")).

๐Ÿ‘‰ Learn more about Ethereum transactions


This guide covers balance checks, sending transactions, and mining in Go Ethereum. For advanced topics like smart contracts, stay tuned for Part 4!

๐Ÿ‘‰ Explore Ethereum development tools