๐Ÿ”— Run your own local xDai node (Updated for London hardfork)

Artboard Copy 9

Recently I encountered some unpleasant lags and outages with some of the publicly available RPCs for xDai. So I looked up how to run my own node on a local machine and connect Metamask directly to this node.

Now I interface smoothly with the xDai chain. With some help from :taco: now you too can become a noderunner! :sunglasses:

โšก๏ธ How to upgrade from 3.0.1 to 3.2.5

Upgrading from OpenEthereum 3.0.1 to 3.2.5 entails a database upgrade which itself requires a bit of terminal work. The upgrade tool is and instructions is found at openethereum/3.1-db-upgrade-tool.

I might cover the upgrade path in more detail in a later update if need be. If youโ€™re not comfortable with the steps of the upgrade tool you may find and delete the chain data and download it once more.

โšก๏ธ How to upgrade from 3.2.5 to 3.3.0

The upgrade path to 3.3.0 should be as simple as gracefully shutting down the openethereum process (Ctrl-C) and replace version 3.2.5 with the version described below.

1. Get the binary :inbox_tray:

Find your build of openethereum version 3.3.0. (Though only a release candidate, this is the officially recommended version for anticipating the hardfork)

:penguin: openethereum-linux-v3.3.0.zip

:green_apple: openethereum-macos-v3.3.0.zip

:framed_picture: unfortunately there are no Windows builds at the time of writing

1.1 โ€ฆor source for compiling yourself :nerd_face:

:fountain: v3.3.0.zip

2. Extract the files :package:

Get it done.

3. Open up your terminal app :desktop_computer:

It may look like this one:

Group

3. Locate the binary :female_detective:

Find the little guy.

4. Run it :gear:

Like so

./openethereum --chain xdai --jsonrpc-port=8545 --jsonrpc-cors=all --jsonrpc-interface=all --jsonrpc-hosts=all --jsonrpc-apis=web3,eth,net,parity --ws-interface=all --ws-apis=web3,eth,net,parity,pubsub --ws-origins=all --ws-hosts=all --ws-max-connections=10 --max-peers=100

:bulb: If youโ€™re on Windows your binary will be called openethereum.exe instead.

5. Sync :chains:

Now wait for the ~30 GB of blockchain data to be downloaded.

The program may throw some errors, especially in the beginning, but these are mainly related to running a real validator node which weโ€™re not doing here.

Once it starts syncing, itโ€™ll look like this:

Syncing #14889406 0x6a10โ€ฆe8d8    42.97 blk/s  204.1 tx/s   34.6 Mgas/s     76+ 2566 Qed  #14892053    4/25 peers   5 MiB chain 132 MiB db 41 MiB queue 8 MiB sync  RPC:  0 conn,    3 req/s,  327 ยตs`

And once youโ€™re completely sync, itโ€™ll look like this:

Imported #14892107 0x7963โ€ฆ1c14 (7 txs, 2.59 Mgas, 48 ms, 3.73 KiB)
   4/25 peers   6 MiB chain 131 MiB db 0 bytes queue 7 MiB sync  RPC:  0 conn,    2 req/s,  278 ยตs```

6. Hook it up to Metamask :fox_face:

Now youโ€™re ready to switch over to your brand new RPC. Fire up Metamask, go to Settings :point_right: Networks, then Add Network.

Fill out the form like so:

Local xDai
http://localhost:8545
100
xDai
https://blockscout.com/poa/xdai/

Hit Save.

Make sure the new network is selected in the Networks dropdown.

7. See it in action :open_book:

Your next transaction will pass through your node looking something like this:

Transaction mined (hash 0x0000000000000000000000000000000000000000000000000000000000000000)

8. Cheers, you made it :tada:

:paperclip: Notes

  • Exit the openethereum process by pressing Ctrl+C.
  • Keep your node synced before using it. The main drawback of running it on your own machine is that the chain state needs resyncing after, for example, system hibernation. The RPC will still work, but it will only show the last synced state.
41 Likes

Dude this is awsome thanks for this!!!

1 Like

Iโ€™ve been meaning to do this for a long time and couldnโ€™t find time to do this, and it was also due to the lack of a tutorial like you delivered.

Many thanks :slight_smile:

1 Like

Great guide! You use this to avoid problems with public RPCโ€™s, as I seeโ€ฆ May I ask, what do you think are the drawbacks for running the node on your own machine?

Thanks guys :slightly_smiling_face:

@FriedRengi The main drawback of running it on your own machine is that the chain state needs resyncing after, for example, system hibernation. The RPC will still work, but it will only show the last synced state.

3 Likes

Thank you very much for the answer!

Thank you very much๏ผ๏ผ๏ผ

You Gem of an individual!

Thanks a lot for this!!! :honey_pot: :honey_pot: :honey_pot:

1 Like

One drawback to consider is your broadcasting the IP address of your box, with an open port, to the world. Before hackers can empty wallets, etc, they have to find them, thus any blockchain node is a high probability target.

If your using a machine at home with other stuff on the drives, make sure to do backups off the machine. If a box gets rootkited, etc, its too late for backups before wiping the disks.

7 Likes

WOW! what useful thread!!! this info is literally a gold mine, muchas gracias :100::raised_hands:

As a suggestion, any services like a blockchain client, http server, etc, on a public facing open port, should not be installed on a user account with root/sudo/admin privileges, like in the tutorial screen shot. Any successful privilege escalation exploit, script kiddie 101, results in the hacker getting root. Game over.

Create a new user account with no admin privileges & matching user group:

$ sudo useradd -m -s /bin/bash xdai
$ sudo groupadd xdai

Restrict read/write/execute permissions to the non-privileged user account(change folder paths to suit):

$ sudo chown -R xdai:xdai /opt/xdai_node
$ sudo chmod -R 750 /opt/xdai_node

Login to non-privileged account:
$ su - xdai

cd to client folder & start client:
$ ./openethereum

Now any privilege escalation, is in theory, restricted to the user with no admin/sudo power & only has write/execute permissions in the xdai client folder. So now, instead of 101 security issues, you only have 100 :slight_smile:

7 Likes

nice thanks for the guide

Publicly available ports arenโ€™t required for running a simple local node though. I have zero public facing ports open in my network.

5 Likes

Thanks for sharing!!

cool ,I wanna try it

thatโ€™s cool,thank your sharing

A nice write up, thanks for sharing.

Might be worth running in a Docker container or small VM in the cloud to keep it online, there could be free tiers that are sufficient.

1 Like

Nodes consume a lot of bandwidth pretty constantly. When I ran an Eth1 node in the cloud I banged into my bandwidth limits pretty quickly.

Think about 1GB an hour of ambient transfer.

2 Likes

good! It help me do the best in xdai network!

OH, thank you for that work!