[Framework Tutorial 1] — How to run and prepare Geth Node for back-end integration

0xcert
0xcert

--

The goal of this tutorial is to show you how to install and correctly set up the Ethereum Geth node for back-end usage.

In this tutorial, you will learn:

  • Which Ethereum networks exist
  • How to install Geth
  • How to run Geth
  • How to create a new account (wallet)

For the purpose of this tutorial, we assume that you have basic computer knowledge and basic blockchain knowledge. All the examples below are for Mac OS, whereas setup on Windows or Linux is very similar.

Ethereum networks

Ethereum has one main network where all the magic happens but also employs many other networks built for testing purposes. Listing all of them in this piece would have additional value, therefore, we will only mention the most commonly used networks:

  1. Mainnet
    Mainnet is the production network of Ethereum. You can get ETH by mining it or buying it on exchanges.
  2. Ropsten
    Ropsten is a test network that most closely resembles the Mainnet. It uses the same proof of work, and it’s supported by both Geth and parity nodes. Since test ETH on this network is mined in the same way as on the Mainnet and since they are easily obtained without any value, this network is susceptible to spam attacks. You can get Ropsten test ETH here, here or mine it yourself.
  3. Rinkeby
    Rinkeby testnet uses proof of authority, meaning you cannot get test ETH unless you authenticate your identity. This is done by publicly linking an Ethereum address with a social media account like Facebook, Twitter or Google Plus. This makes it much harder to attack the network since getting large amounts of ETH is a hassle. Rinkeby is only supported by Geth nodes. You can get Rinkeby test ETH here.
  4. Kovan
    Much like Rinkeby, Kovan is a testnet that uses proof of authority and subsequently has the same characteristics. The main difference is that Kovan is only supported by parity nodes and that you authenticate yourself via GitHub. You can get Kovan test ETH here.

There are other networks like Goerli, Sokol, etc., which all have some specific purpose but the ones listed above are currently the most used.

In this tutorial, we will connect to the Ropsten testnet.

Installing Geth

There are many ways of installing Geth. You can do it via packet manager like homebrew on MacOS or PPA on Ubuntu, you can directly download it, run it in a docker or build it from source code yourself.

For this tutorial, we will directly download it since this makes the process most similar for all operating systems.

So let’s download it. We will be downloading Geth 1.8.22 for MacOS (the latest stable version at the time of writing). Now, all we have to do after downloading it is to unzip it. That’s it.

When using nodes, please make sure to keep them up to date.

Run Geth

Geth has a multitude of options for starting it. But since we are running it for a back-end project, we want specific things like:

  • Running the Ropsten network
  • Enabling RPC communication so that we can communicate with it
  • Running different Ethereum APIs like personal (to unlock/control accounts), net (to check network status), etc.
  • Opening a console so that we can directly communicate via web3
  • Light sync mode (it is better to run a full node, but for a quick setup for the tutorial, the light mode should do the job)

To achieve this, we will run the following command:

./Geth console --testnet --syncmode "light" --rpc --rpcaddr "localhost" --rpcport "8545" --rpccorsdomain "*" --rpcapi="db,eth,net,web3,personal"

We need to run this command via a terminal at the location of the unzipped Geth folder.

This will directly bring us into the Geth console. By typing in net we can see if we have connected to any peers, and by typing eth.syncing we can check whether the node is currently syncing.

You may find that your node will not start syncing. The best way to combat this is to add peers manually. Here is a list of Ropsten light peers. This list and the list of peers for other networks is maintained by the good Samaritan Rocky Fikki.

All you need to do is copy the contents of the gist into the console, and the sync should start.

Create a new account (wallet)

Now that we have the node console open, we can create a new wallet for ourselves. We do this by writing:

web3.personal.newAccount()

into the console. This will prompt us to input a passphrase. Choose a strong passphrase, write it down and save it in a secure place. The resulting hash we get is our public key/wallet — copy it since you will probably need it.

Now that you have an account created, you can get some test ETH from faucets linked in the Ethereum networks sections. You should now be ready to start making JSON-RPC calls or use the 0xcert Framework to do the dirty work for you.

The Framework is freely available on our GitHub and comes with a thorough documentation. Feel free to use it for you next dapp and let us know how it worked for you on our Gitter chat.

Read more of the Dapp series:

Part #1 — Intro: What are dapps
Part #3 — Guide: How to develop a dapp and white is it so complicated

Originally published at 0xcert.org.

--

--

0xcert
0xcert
Editor for

Your ID, degree, artwork or house. 0xcert-ified on the blockchain⛓→ https://0xcert.org/