Skip to content

Instantly share code, notes, and snippets.

@cywf
Created February 1, 2023 16:53
Show Gist options
  • Save cywf/fd277cdce89988d8e35830d0c495a6ae to your computer and use it in GitHub Desktop.
Save cywf/fd277cdce89988d8e35830d0c495a6ae to your computer and use it in GitHub Desktop.

Energy Web Foundation

Guide for setting up and running a full node of the Energy Web Chain main network or Volta test network locally

What does it mean to run a node?

A 'client' is software that implements a blockchain's protocols and allows you to connect directly with the blockchain - that is to read data from the blockchain or initiate transactions on the blockchain, such as transferring tokens. Anyone can create client software, as long as it implements that blockchain's official protocols. Ethereum's protocols are specified in their yellow paper, and there are a number of Ethereum clients to choose from.

A node is any machine that is actively running client software and is connected to the blockchain. Blockchain is often called a “peer-to-peer” network, because its network is made up of many peers running nodes simultaneously that are connected to each other.

Depending on if you are running a full node, a light node, or an archive node (see the differences between these nodes here), your client will sync with the current state of blockchain and then continue to execute every transaction that is added to the blockchain. Essentially it is having a live copy or version of the blockchain running locally on your machine. Depending on the blockchain you are you connecting to, this can take up large amounts of space and take a long time to retrieve and sync the history of the chain on your machine. For example, synching with the Energy Web chain will require much less resources than syncing with the Ethereum mainnet, as it is a much larger and longer-running blockchain.

What do I need to run a node?

To run a node, you need to install the client software. The Energy Web mainnet and Volta testnet both use the OpenEthereum client (formally known as Parity), because it supports the Authority Roundtable (AuRa), which is a consensus algorithm specifically for Proof-of-Authority (PoA) blockchains. You can read more about the PoA consensus algorithm and why we implemented it for the Energy Web Chain here.

Benefits to running a local node

  1. The more nodes there are, the more secure the system is as a whole. Blockchains are decentralized technology, so by design the system performs better if there are multiple instances of it rather than just one. The more nodes there are, the less points of failure or opportunities for malicious action.
  2. Your transactions are more direct and more secure. Software that provides intermediary connections to the blockchain like Infura or MetaMask are, like any other web-based software, susceptible to downtime or error. By connecting to the blockchain yourself, you are removing your dependency on external providers for secure and direct connection. You also do not expose your public keys to the browser.
  3. You can self-verify transactions. You have part or all of the blockchain running on your node, so you can query the chain for transactions directly (and as often as you want) rather than relying on a user interface like a block explorer. Your queries can be more specific and efficient, giving you only the information that you need, for example, ‘how many transactions did addresses X, Y and Z send during this time period on each day for the last 30 days?’
  4. You are not subject to rate limits. Infura (and therefore MetaMask, as it implements Infura to connect to the blockchain) does have rate limits for JSON RPC requests. If your development requires a lot of requests to the blockchain, running a local node may be more efficient.

Run a local node using the command line

  1. Download Parity/OpenEthereum client v3.3.0-rc.11
  2. Download and save the chain config to your local machine. The chain config for Volta Test Network is here. The chain config for Energy Web Main Network is here.
  3. Run the following command in your terminal. Provide the path to the chain config that you want to use. The following command references the Volta chain config:
parity --chain /path/to/chainconfig/volta.json

Your local node should start:

2021-09-21 09:54:03  Starting Parity-Ethereum/v2.7.2-stable-d961010f63-20200205/x86_64-apple-darwin/rustc1.41.0
2021-09-21 09:54:03  Keys path /Users/whitneypurdum/Library/Application Support/io.parity.ethereum/keys/Volta
2021-09-21 09:54:03  DB path /Users/whitneypurdum/Library/Application Support/io.parity.ethereum/chains/Volta/db/d94a0a739a3e416a
2021-09-21 09:54:03  State DB configuration: fast
2021-09-21 09:54:03  Operating mode: active
2021-09-21 09:54:03  Not preparing block; cannot sign.
2021-09-21 09:54:03  Configured for Volta using AuthorityRound engine
2021-09-21 09:54:04  NAT mapped to external address 108.4.233.48:30303
2021-09-21 09:54:04  Public node URL: enode://a29dd8b0d114e099a7b1ef8045fbbeac632539001ac9d4350b024f9a3f189ee9a270ba64345a6878deaa3b150afce755b8e8abb8d7e49f2db7ab561742a3e698@108.4.233.48:30303
2021-09-21 09:54:05  Not preparing block; cannot sign.
2021-09-21 09:54:18  Snapshot initializing (7/2085 chunks restored, 0%)        #0    4/25 peers   920 bytes chain 216 KiB db 0 bytes queue 5 KiB sync  RPC:  0 conn,    0 req/s,    0 µs
2021-09-21 09:54:23  Snapshot initializing (21/2085 chunks restored, 1%)        #0    5/25 peers   920 bytes chain 216 KiB db 0 bytes queue 5 KiB sync  RPC:  0 conn,    0 req/s,    0 µs

Connect your local node to MetaMask

Connect your MetaMask to the Volta Test Network or Energy Web Chain via remote RPC. You can read how to do this here. Get the URL of your MetaMask account. You can do this by clicking the settings dropdown and selecting "Expand View."

When the view is expanded, copy the URL in the browser

Run the following command in your terminal:

parity --chain path/to/chainconfig/volta.json --jsonrpc-cors METAMASK URL  

Running a local node using Docker

This section describes minimal setup to run an RPC node locally or on the server using Docker container run with docker-compose. This is solely for development purposes, it's not a production grade recommendation.

See OpenEthereum documentation for Docker: OpenEthereum Documentation - Docker

Prerequesits

Hardware Requirements

You need to meet OpenEthereum hardware requirements and have enough disk space to store database snapshots (which will grow in time). OpenEthereum - EthHub

  • Multi-core CPU
  • 4GB RAM
  • SSD drive and at least 150GB free space
  • A decent DSL connection is required

Setup

  1. Verify that prerequisites are installed:
docker --version 
docker-compose --version 
curl --version
  1. Create working directory:
mkdir openethereum 
cd openethereum 
mkdir -p chain-data/chains
  1. Create docker-compose.yaml file:
cat > docker-compose.yaml << 'EOF'
version: '3.8'
services:
  openethereum:
    image: openethereum/openethereum:v3.3.0-rc.11
    restart: always
    ports:
      - 8545:8545
      - 8546:8546
      - 30303:30303
      - 30303:30303/udp
    command:
      --jsonrpc-interface all --chain /config/chainspec.json
      # Uncomment this if connecting local node to MetaMask
      # --jsonrpc-cors chrome-extension://URL-OF-METAMASK
    volumes:
      - ./chain-data:/home/openethereum/.local/share/io.parity.ethereum/
      - ./chainspec-volta.json:/config/chainspec.json:ro
      # chainspec file should be changed if using EWC
      # - ./chainspec-ewc.json:/config/chainspec.json:ro
EOF

Full specification for configuration options can be found here: OpenEtherum Documentation - Configuration OpenEtherum

  1. Download the chainspec file. Note that there are different chainspec files for the Volta Testnet and the Energy Web production chain

Volta Testnet chainspec:

curl -L https://raw.githubusercontent.com/energywebfoundation/ewf-chainspec/master/Volta.json -o chainspec-volta.json

Energy Web Chain (production) chainspec:

curl -L https://raw.githubusercontent.com/energywebfoundation/ewf-chainspec/master/EnergyWebChain.json -o chainspec-ewc.json
  1. Download database snapshot - this takes some time and requires resources due to the size of the .tar file, but it will speed up synchronization process.

*Note that this step is optional. If you do not download the database snapshot, move to Step 7.

Volta (depending on your internet connection ~1 hour download time for us):

curl -L -C - https://chain-download.energyweb.org/volta -o ./chain-data/chains/volta.tar

Energy Web Chain (production) (30 minutes download time for us):

curl -L -C - https://chain-download.energyweb.org/ewc -o ./chain-data/chains/energywebchain.tar
  1. Unpack database snapshot.

*Note that this step is optional. If you did not complete Step 5, skip this step and move to Step 7. Volta:

sudo tar -xvf ./chain-data/chains/volta.tar -C ./chain-data/chains

Energy Web Chain (production):

curl -L -C - https://chain-download.energyweb.org/ewc -o ./chain-data/chains/energywebchain.tar
  1. Set permissions:
sudo chmod -R 777 chain-data
  1. Start container:
docker-compose up -d
  1. Examine logs:
docker-compose logs --tail 20 openethereum

The log output should be similar to the following (sometimes the logging output does not appear immediately, wait some time):

openethereum_1  | 2021-11-03 15:26:22 UTC Starting OpenEthereum/v3.3.0-rc.11-stable/x86_64-linux-musl/rustc1.47.0
openethereum_1  | 2021-11-03 15:26:22 UTC Keys path /home/openethereum/.local/share/io.parity.ethereum/keys/Volta
openethereum_1  | 2021-11-03 15:26:22 UTC DB path /home/openethereum/.local/share/io.parity.ethereum/chains/Volta/db/d94a0a739a3e416a
openethereum_1  | 2021-11-03 15:26:22 UTC State DB configuration: fast
openethereum_1  | 2021-11-03 15:26:22 UTC Operating mode: active
openethereum_1  | 2021-11-03 15:26:22 UTC Not preparing block; cannot sign.
openethereum_1  | 2021-11-03 15:26:27 UTC Configured for Volta using AuthorityRound engine
openethereum_1  | 2021-11-03 15:26:32 UTC Error reading node table file: Error("EOF while parsing a value", line: 136, column: 13)
openethereum_1  | 2021-11-03 15:26:32 UTC Listening for new connections on 127.0.0.1:8546.
openethereum_1  | 2021-11-03 15:26:35 UTC Not preparing block; cannot sign.
openethereum_1  | 2021-11-03 15:26:37 UTC Public node URL: enode://fd35fd56944ed2150d019ab7f9c42e48c7dce5409af0c57b3f295fd083c04492c7b95d50bab89cc44e8650c3a5a877573c3e8b6a50b6c3553d07046330a86fe4@172.
  1. After some, you will sync with the network. Until a full sync, you will see be in a "syncing" state:
12021-11-03 15:33:42 UTC Syncing #14332274 0x2b0d...23c2 0.00 blk/s 0.0 tx/s 0.0 Mgas/s 0+ 0 Qed LI:#14332276 1/25 peers 72 KiB chain 0 bytes queue RPC: 0 conn, 0 req/s, 87 µs
  1. Check the database synchronization status in the command line using OpenEthereum's 'eth-syncing' module: OpenEthereum Documentation - The eth Module
curl --data '{"method":"eth_syncing","params":[],"id":1,"jsonrpc":"2.0"}' -H "Content-Type: application/json" -X POST localhost:8545

The output will show current synchronization status:

{"jsonrpc":"2.0","result":{"currentBlock":"0xdab79f","highestBlock":"0xdac9d2","startingBlock":"0xdab172","warpChunksAmount":null,"warpChunksProcessed":null},"id":1}

It will take some time to fully sync with the current state of the blockchain. When the synchronization is finished status will be:

{"jsonrpc":"2.0","result":false,"id":1}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment