This is a guide on how to quickly setup and sync a Moonbeam node on a hosted server. Running a node on a Moonbeam-based network allows you to connect to the network, sync with a bootnode, obtain local access to RPC endpoints, and more. In this tutorial, we will be using systemd to set up a service to run the node because we will be using Ubuntu Linux. If you want to or need to run a different OS know that you can run the node with Docker just as easily.
Topics in order are
- Creating a Hetzner Server
- Enabling SwapFile (optional)
- Downloading Snapshot (optional)
- Service and Binary Setup
- Configuration File
- Running the Service
Creating a Hetzner Server
If you want to run your node on a server then Hetzner is your best bet. There are other options out there like Digital Ocean and Vultr, but neither of them gets to the price point that Hetzner provides.
First Create an account at Hetzner. Then login at hetzner.cloud and bookmark this page. Go ahead and create a new project naming it whatever you like. Once it is created click on it and then click on ADD SERVER. In the options pick any location you want and Ubuntu for the Image.
Next pick the type standard and the option CPX41 which has 240 GB of storage.
Current requirements for a node based on the moonbeam docs say that we need an 8 Core CPU, 16 GB Ram, and a 1 TB SSD. These requirements are a bit over the top as they are intended for Validators/Collators and are future-proof. The main minimum specs we need to worry about is storage. As of writing this post a Full node on moonbeam currently needs roughly 200 GB of SSD storage (160 GB if you don’t need to full block history). This storage requirement will grow with time so keep that in mind. For now, we can use the CPX41 option as it meets the requirements, but most importantly the storage.
Node: Going under the 8 Core and 16 GB Ram requirements will work fine for a noncritical node and will only result in slower sync time. However, it is not recommended for Validators/Collators.
Next, create and add your SSH key. If you do not know how I suggest using ssh-keygen. An article explaining “How to Use ssh-keygen to Generate a New SSH Key?”.
Once the SSH key is added leave everything else default and click CREATE & BUY NOW
With the server created we can now login using ssh. On Linux, it would look something like this
You should then get a response as such.
Once logged in I recommend updating the server using
sudo apt update && sudo apt upgrade
and rebooting if necessary.
Enabling SwapFile (optional)
Creating a Linux SwapFile is not necessary but is nice to have if you are running other memory-intensive programs on your server. Using a swap is a very useful way to extend the RAM because it provides the necessary additional memory when the RAM space has been exhausted and a process has to be continued. If you want to create a swap file run the following commands.
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
Open the /etc/fstab file
sudo nano /etc/fstab
add the following to the end of the file
/swapfile swap swap defaults 0 0
Save the file with
Ctrl+s and close it with
To verify that the swap file is active use
sudo swapon - show
It should result in something like the following.
NAME TYPE SIZE USED PRIO
/swapfile file 1024M 507.4M -1
Downloading Snapshot (optional)
Something that can GREATLY increase sync time is downloading an already synced snapshot of either the moonbeam para-chain, the relay chain, or both. If you need your node up quickly or don’t want to bother waiting this is your best option. My current recommendation is to use Certhum’s backups as they are updated regularly. If you want to sync the node from scratch skip down to the section Service and Binary Setup.
Now Because the files are quite large and our drive is roughly 240 GB we will not be able to download and unzip the files without running out of storage. The workaround for this is attaching a volume to our server and downloading the backup there. In Hetzner click on the server, you created and go to the VOLUMES tab on the left. Then click Create Volume and set the storage to 300 GB and name it volume1. Now click CREATE & BUY NOW. Don’t worry about the cost, we will be deleting the volume after we download and unzip the backups.
After the volume is created go back to where you logged into the server and configure the volume by following the commands given in the settings of the volume on Hetzner.
This mounts the volume at
/mnt/volume1 where we will download the backups. To download the most recent backup use
Moonbeam Relay Chain Backup
Download the backup to volume1. This will take time depending on your network speed.
wget -O /mnt/volume1/moonbeam-polkadot-backup.tar.zst https://db.certhum.com/moonbeam-polkadot-backup.tar.zst
Note: If the download fails or gets canceled reenter the command with the -c flag to continue the download from where it left off.
next download the sst
wget -O /mnt/volume1/moonbeam-polkadot-sst.dict https://db.certhum.com/moonbeam-polkadot-sst.dict
install zstd (ZSTD lets you specify how many processors you want to assign to the job)
sudo apt install zstd
Create the directory for the database in var/lib
sudo mkdir -p /var/lib/moonbeam-data/polkadot/chains/polkadot/db
and finally unzip the backup to the database using
sudo tar -I 'zstd -vd -T0 -D /mnt/volume1/moonbeam-polkadot-sst.dict' -xvf /mnt/volume1/moonbeam-polkadot-backup.tar.zst -C /var/lib/moonbeam-data/polkadot/chains/polkadot/db - strip-components=7
This should take some time so wait until it is finished.
Moonbeam Parachain RocksDB Backup
The process for downloading the Moonbeam Parachain is almost the same as the Relay Chain so I won’t go into as much detail.
wget -O /mnt/volume1/moonbeam-backup-archive.tar.zst https://db.certhum.com/moonbeam-backup.tar.zst
wget -O /mnt/volume1/moonbeam-sst.dict https://db.certhum.com/moonbeam-sst.dict
sudo mkdir -p /var/lib/moonbeam-data/chains/moonbeam/db
sudo tar -I 'zstd -vd -T0 -D /mnt/volume1/moonbeam-sst.dict' -xvf /mnt/volume1/moonbeam-backup-archive.tar.zst -C /var/lib/moonbeam-data/chains/moonbeam/db - strip-components=6
Now that we have our backups unzipped we can delete the volume so that we don’t have to pay monthly for it. To delete the volume first detach the volume and then delete it.
Once detached you need to go to the left side tab click on Volumes and then again go to setting add click Delete
⚠️ Make Sure the Volume is Deleted or you will be charged monthly for it! ⚠️
Service and Binary Setup
The following commands will set up everything regarding running the service.
- Create a service account to run the service:
adduser moonbeam_service - system - no-create-home
- Create a directory to store the binary and data:
sudo mkdir /var/lib/moonbeam-data
- Download the Latest Moonbeam Binary:
sudo wget -O /var/lib/moonbeam-data/moonbeam https://github.com/PureStake/moonbeam/releases/latest/download/moonbeam
- Make sure you set the ownership and permissions accordingly for the local directory that stores the chain data:
sudo chmod +x moonbeam
sudo chown -R moonbeam_service /var/lib/moonbeam-data
The next step is to create the systemd configuration file. Depending on your needs there are a few different options between creating a full node or a pruning node. If you used the backups above you will need to have state-pruning set to archive. If you want a pruned node you can remove
- state-pruning=archive from the config file and the node will default to pruning the state to the last 256 blocks. More info about flags can be found here.
Note: Full nodes a.k.a “archive” nodes keep the full history of the chain and require a bit more space than pruned state nodes. In this case roughly 40GB.
Create the config file at /etc/systemd/system/moonbeam.service
sudo nano /etc/systemd/system/moonbeam.service
Add the following to the file changing YOUR-NODE-NAME to a name you want.
Description="Moonbeam systemd service"
--port 30333 \
--rpc-port 9933 \
--ws-port 9944 \
--execution wasm \
--wasm-execution compiled \
--trie-cache-size 0 \
--base-path /var/lib/moonbeam-data \
--chain moonbeam \
--name "YOUR-NODE-NAME" \
--port 30334 \
--rpc-port 9934 \
--ws-port 9945 \
--execution wasm \
--state-pruning 1000 \
--name="YOUR-NODE-NAME (Embedded Relay)"
Save the file with
Ctrl+s and close it with
Running the Service
The last thing to do is enable and run the service.
systemctl enable moonbeam.service
systemctl start moonbeam.service
Check the output logs from the node with
journalctl -f -u moonbeam.service
Your node should now be running and should start back up if you ever reboot the system. Depending on if you downloaded the optional backups complete syncing of the node should take around 2-3 days.
If you ever need to stop the service do it with
systemctl stop moonbeam.service
and if you want to disable the service from starting on reboot
systemctl disable moonbeam.service
View your nodes telemetry by searching the name of your node at Polkadot’s Telemetry dashboard.