IN previous article you learned how to set up a fully synced blockchain node in 10 mins. Is time to learn how to perform a transaction on Ethereum network using GETH CLI.

This is Part 2 of our #learning-ethereum-blockchain-series. To be on the same page, action all the steps from previous article first.

Done? Perfect.

At this point you know:

  • how to run a fully synced Ethereum blockchain node
  • how to attach GETH console
  • how to query a balance of an Ethereum account
geth attach ipc:/home/enchanter/.gophersland_ethereum_r1/geth.ipc
eth.getBalance("0xceee57f2b700c2f37d1476a7974965e149fce2d4")

> 7500000000000000000

I do but wait for a second Lukas. Why 7.5ETH is displayed as 7500000000000000000 in the Geth console?

Ether vs Wei

Ethereum Virtual Machine is not supporting decimals, neither floats. Apparently, calculations in finance are easier in integers

Therefore to be able to send a fraction of 1 ETH, Ethereum foundation decided to create their own metric system where the smallest unit would be 1 Wei and 1 Ether is 1e18 of Wei.

But no worries, there are tools that can make your life easier. For example, I highly recommend the Ether to Wei online converter. https://etherconverter.online

In order to send 15$ worth of Ether, where 1 ETH == 200$, you would make a transaction sending 0.0740 ETH which would be, and must be represented in Wei as 74000000000000000.

Online Eth to Wei converter:

online converter

Overview of the Ethereum metric system:

ethereum metric system

Practice makes mastery. Let’s actually send 74000000000000000 Wei (15$) to another account.

Sending Ether to another account using GETH CLI

In on terminal, remember to run a fully synced blockchain node:

geth --rinkeby --datadir=~/.gophersland_ethereum_r1 --port=30304 --cache=2048 --rpc --rpcport=8546 --rpcapi=eth,web3,net,personal --syncmode=fast

In another terminal, we will create our second Ethereum account, exactly like in Part 1.

ls -la ~/.gophersland_ethereum_r1/keystore/

> drwx------ 2 enchanter enchanter 4096 sep 24 15:36 .
> drwx------ 4 enchanter enchanter 4096 sep 24 15:26 ..
> -rw------- 1 enchanter enchanter  491 sep 24 15:36 UTC--2018-09-24T13-36-43.069452577Z--ceee57f2b700c2f37d1476a7974965e149fce2d4

geth --datadir=~/.gophersland_ethereum_r1 account new

> INFO [09-24|15:36:33.566] Maximum peer count                       ETH=25 LES=0 total=25
> Your new account is locked with a password. Please give a password. Do not forget this password.
> Passphrase: 
> Repeat passphrase: 

> Address: {7aa4a14286a25e3a275d7a122c23dc3c107a636a}

ls -la ~/.gophersland_ethereum_r1/keystore/

> drwx------ 2 enchanter enchanter 4096 oct 25 20:14 .
> drwx------ 4 enchanter enchanter 4096 oct 25 19:48 ..
> -rw------- 1 enchanter enchanter  491 sep 24 15:36 UTC--2018-09-24T13-36-43.069452577Z--ceee57f2b700c2f37d1476a7974965e149fce2d4
> -rw------- 1 enchanter enchanter  491 oct 25 20:14 UTC--2018-10-25T18-14-39.639746412Z--7aa4a14286a25e3a275d7a122c23dc3c107a636a

Now, let’s attach the Geth Console to the currently running blockchain node as we did in the previous section in order to transfer 15$ to this newly created account by executing eth.sendTransaction command.

geth attach ipc:/home/enchanter/.gophersland_ethereum_r1/geth.ipc

eth.sendTransaction({from: "0xceee57f2b700c2f37d1476a7974965e149fce2d4", to: "0x7aa4a14286a25e3a275d7a122c23dc3c107a636a", value: "74000000000000000"})

Error: authentication needed: password or unlock.

You should get an error. This is because sending Ether is a “transaction” and a transaction changes state, costs gas, spends funds. Which means it needs to be signed with our Private Key that is stored in the keystore and in order to decrypt the key we must provide a password, in other words, unlock the account.

Execute the following command to unlock your account for next 60s and execute the sendTransaction command once again.

web3.personal.unlockAccount(web3.personal.listAccounts[0], null, 60)
eth.sendTransaction({from: "0xceee57f2b700c2f37d1476a7974965e149fce2d4", to: "0x7aa4a14286a25e3a275d7a122c23dc3c107a636a", value: "74000000000000000"})

We could have also passed the password as a second argument, instead of null, but this way is safer as your password is only in a buffer and not stored in any log or visible on the screen.

send_transaction

This time the command succeeded and a Transaction hash receipt was returned! Ou yeah!

As we are connected to the Rinkeby network, we can take advantage of the Rinkeby GUI explorer to check the status of this transaction, gas spent, gas price etc.

  1. Open the explorer
  2. Paste the Transaction receipt hash to the search bar
  3. Done, we spent 21,000 of Gas (standard for sending funds) and the Transaction succeeded!

rinkeby explorer

You can now query the balances of both accounts and see the changed state:

eth.getBalance("0xceee57f2b700c2f37d1476a7974965e149fce2d4")
> 7425979000000000000

eth.getBalance("0x7aa4a14286a25e3a275d7a122c23dc3c107a636a")
> 74000000000000000

Works like a charm. Well done Sir/Madam.

Summary

Congratulation, you:

  • learned the difference between Ether and Wei and how to convert them
  • submitted your first transaction across global Ethereum test network, Rinkeby

Call to action

Rumors say, I should skillfully include a CTA at the bottom of the page but I hate luring people so here is the straight truth.

I am going to write a lot about the knowledge acquired by reverse engineering several popular, highly successful Go projects such as go-ethereum, buffalo, go-ipfs and others.

Join me on the path and explore the Go and blockchain world by subscribing to the newsletter below!

Thank you,
Your Gopher Lukáš