Joining the Ethereum Network Locally and on AWS

Rahul Agarwal
CoinsBench
Published in
4 min readMar 9, 2022

--

Photo by DrawKit Illustrations on Unsplash

As a first step I would suggest to read this prior post for some basics and using just your browser to get started. In this post I am using the Go lang based Ethereum client, geth, which is one of the most popular ones. Using geth, you can join the Ethereum network as one of the nodes and I am doing this for the Rinkeby test network.

Locally

On Mac:

% brew install ethereum

You can find other options for your favorite platform.

First create some local EAO addresses using clef. The chainid 4 is Rinkeby. The address will be used subsequently.

% clef newaccount --keystore keystore... accept warning and create password
...
INFO [03-07|22:00:02.920] Your new key was generated address=0x5c065A20B9156FE1BbE3fffBF85db60E727b9d4e% clef --keystore keystore --configdir clef --chainid 4... accept warning and leave it runningINFO [03-07|22:17:12.298] IPC endpoint opened url=clef/clef.ipc------- Signer info -------
* extapi_version : 6.1.0
* extapi_http : n/a
* extapi_ipc : clef/clef.ipc
* intapi_version : 7.0.1
...

Then in a new terminal window start geth. Clef provides the local EOA and it signs any request when using it as the sender.

% geth --datadir geth --signer=clef/clef.ipc --rinkeby --syncmode light --http --v5disc...
Block synchronisation started
...Imported new block headers count=192 elapsed=23.545ms number=9,602,112 hash=a07a88..28c428 age=4mo1d2h
...

Now you need to wait for a bit. Check the latest block number on Rinkeby Etherscan. Once your local is caught up you will be able to do some transactions. The number = 9,602,112 is the block number above. Looks like it syncs last 4 months in light mode.

Next, in a new terminal window, attach to the local instance as follows.

% geth attach http://127.0.0.1:8545
...
> net
{
listening: true,
peerCount: 1,
version: "4",
getListening: function(callback),
getPeerCount: function(callback),
getVersion: function(callback)
}

From my Meta Mask account I sent 0.2 to this local EAO address I created in clef. You can then query it with web3.

> web3.fromWei(eth.getBalance("0x5c065A20B9156FE1BbE3fffBF85db60E727b9d4e"), "ether")0.2

Then send some back.

> eth.sendTransaction({from:"0x5c065A20B9156FE1BbE3fffBF85db60E727b9d4e",to: "0x4D8aD277b7F9EF7aB9942b17496bd9fA216ba576",value: web3.toWei(0.1, "ether")})

After you enter this, switch to the terminal with clef. You will need approve it and provide the password.

--------- Transaction request-------------
to: 0x4D8aD277b7F9EF7aB9942b17496bd9fA216ba576
from: 0x5c065A20B9156FE1BbE3fffBF85db60E727b9d4e [chksum ok]
value: 100000000000000000 wei
gas: 0x5208 (21000)
...-------------------------------------------Approve? [y/N]:
> y
## Account password
Please enter the password for account 0x5c065A20B9156FE1BbE3fffBF85db60E727b9d4e
>-----------------------Transaction signed:...

You can now use this for local development or even point Remix to this. This is similar to how you can attach a local python interpreter to a remote notebook like Collab.

AWS Managed Blockchain

There is a “public” managed blockchain option in AWS and basically it looks to run the same geth client as above. I created a node for the same Rinkeby test network.

Start a managed Ethereum node in AWS

It takes a while to become available — similar to local when it has to get all the blocks. While it is deploying goto IAM and create a user so we can connect with the API. Create a user for programmatic access and add the policy: AmazonManagedBlockchainFullAccess. This will give you the access key and secret. Install AWS CLI and AWS Curl.

Configure CLI with the access key, secret, region and I prefer json as output format:

% aws configure
AWS Access Key ID [****************OY5S]:
AWS Secret Access Key [****************KiO3]:
Default region name [us-east-1]:
Default output format [json]:

Now AWS curl will use this setup and do the required HMAC signing of the requests.

I could not figure out how to geth attach to this managed node. The options in their docs look very cumbersome so simple RPC call as follows to get balance of the address I used above on my local. The node HTTP endpoint is from AWS console.

% awscurl --service managedblockchain \-X POST -d '{"jsonrpc": "2.0", "method": "eth_getBalance", "params": ["0x5c065A20B9156FE1BbE3fffBF85db60E727b9d4e","latest"], "id": 1}' \https://nd-fvb...y.ethereum.managedblockchain.us-east-1.amazonaws.com |jq{
"jsonrpc":
"2.0",
"id":
1,
"result":
"0x6a6ea46c275350"
}

Convert his hex to number and balance is indeed what is in Etherscan.

% echo $[0x6a6ea46c275350]29957999999538000

I’m not sure how to use this node further for now. Delete the node so stop incurring cost.

If these topics interest you then reach out to me and I will appreciate any feedback. If you would like to work on such problems you will generally find open roles as well! Please refer to LinkedIn.

--

--