The goal of this Ethereum tutorial series is to show you how to use the 0xcert Framework for building a dapp on the Ethereum blockchain plus creating and managing non-fungible tokens.
In this episode, we wil install and correctly set up the Ethereum Geth node for back-end usage.
(Prefer building on Wanchain? This tutorial should help.)
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 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:
Mainnet is the production network of Ethereum. You can get ETH by mining it or buying it on exchanges.
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.
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.
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.
In this tutorial, we will connect to the Ropsten testnet.
1. Install Geth node
There are many ways of installing Geth node. 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.
2. Run Geth node
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.
3. Create a new Ethereum account (wallet)
In our newly open node console we can create a new wallet for our project. We do this by writing:
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.
If you have questions about the code or you experience trouble developing your dapp, you can ask our developers for help in our Gitter channel.
What comes next?
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.
Check other tutorial episodes, as well.
Framework tutorial for Ethereum #2: Set up Express server with TypeScript for dapp back-end
Framework tutorial for Ethereum #3: Deploy asset ledger
Framework tutorial for Ethereum #4: Create new assets
Framework tutorial for Ethereum #5: Transfer assets
Framework tutorial for Ethereum #6: Atomic operations in asset exchange