Ethereum Network Interaction with Geth

Assuming you have followed along so far and finish the Provisioning section, now it’s time to talk to Ethereum using Geth.

Once Geth is up and in sync with the blockchain, you can attach to it with:

geth attach http://:8545Welcome to the Geth JavaScript console!  instance: Geth/v1.7.1-stable-05101641/linux-amd64/go1.9 
coinbase: 0x0e1e9ce68b3254461a95916c185c37dd65468ab5
at block: 1856113 (Thu, 12 Oct 2017 13:25:06 UTC)
modules: eth:1.0 net:1.0 personal:1.0 rpc:1.0 web3:1.0
>

A fresh installation of Geth won’t have any accounts yet:

> eth.accounts []

You can create an account with the newAccount() function:

> web3.personal.newAccount() 
Passphrase:
Repeat passphrase:
"0x4ffd642a057ce33579a3ca638347b402b909f6d6"
>
> web3.personal.newAccount()
Passphrase:
Repeat passphrase:
"0xa3eebd575245e0bd51aa46b87b1ffc6a1689965a"

You can get the balance of any account with getBalance():

> eth.getBalance("0x4ffd642a057ce33579a3ca638347b402b909f6d6") 0

You can also visit etherscan.io to inspect the address.

To get testnet Ether, you can simply ask a faucet for some:

curl -X POST  \   
-H "Content-Type: application/json" \
-d "{\"toWhom\":\"0x4ffd642a057ce33579a3ca638347b402b909f6d6\"}" \
https://ropsten.faucet.b9lab.com/tap
{
"txHash" : "0x3e5bfb4bc071e4b0e70eedbc7b667ff6a5e7eb5397a21e16582b85848190ae98" }

You’ll get a transaction hash back and you can follow it on etherscan.

After the transaction is mined you will see the balance increase:

> eth.getBalance("0x4ffd642a057ce33579a3ca638347b402b909f6d6") 500000000000000000

You can now send Ether to another account with:

eth.sendTransaction(   
{
from:"0x4ffd642a057ce33579a3ca638347b402b909f6d6",
to:"0xa3eebd575245e0bd51aa46b87b1ffc6a1689965a",
value:100000000000000000
}
)

Again, a transaction hash will come back and you can follow it on etherscan.

Once that transaction goes through we can see the balance of both accounts:

> eth.getBalance("0x4ffd642a057ce33579a3ca638347b402b909f6d6") 
399370000000000000
>
> eth.getBalance("0xa3eebd575245e0bd51aa46b87b1ffc6a1689965a")
100000000000000000

You might also want to wrap those large numbers in a fromWei() function:

web3.fromWei(
eth.getBalance(
"0x4ffd642a057ce33579a3ca638347b402b909f6d6"
),"ether"
)
0.39937

Notice that 0x4ffd doesn’t have exactly 4 Ether. This is because a small amount of Ether is spent on gas to fuel the transaction. In the next section we’ll deploy a contract and talk about gas.

This is an excerpt from Concurrence — Ethereum Network Interaction.

Read more about Concurrence here.

Coinmonks

Coinmonks is a non-profit Crypto educational publication.

Sign up for Cryptoanarchy from Coinmonks

A newsletter that brings you week's best crypto and blockchain stories and trending news directly in your inbox, by CoinCodeCap.com

Create a free Medium account to get Cryptoanarchy in your inbox.

Austin Thomas Griffith

Written by

http://austingriffith.com

Coinmonks

Coinmonks

Coinmonks is a non-profit Crypto educational publication. Follow us on Twitter @coinmonks Our other project — https://coincodecap.com

Austin Thomas Griffith

Written by

http://austingriffith.com

Coinmonks

Coinmonks

Coinmonks is a non-profit Crypto educational publication. Follow us on Twitter @coinmonks Our other project — https://coincodecap.com

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store