Set up custom polygon full node easily

Polygon has excellent documentation for setting up full node in different ways but it might be overwhelming when starting for first time. When I was setting up polygon node on my own, it was quite confusing following the documentation and had to try multiple times. So I feel like I need to list down easiest way possible to run polygon full node perfectly.
These are the key components for running a Polygon Node:
1. Proof of Stake node — Heimdall
2. REST API server — Heimdall
3. EVM node — Bor
So we will setup these three services in this article.
Technical Requirements
Minimum server configuration from documentation
RAM: 16–32 GB
CPU: 4–8 core CPU (t3 xLarge)
Storage: Minimum 1.2TB SSD
These specifications are given in polygon documentation. It can be ideal for testnet but if you are setting up mainnet then you might need about 3TB of SSD when you use snapshots, and I will explain it later why.
And make sure your storage is expandable since we need to expand the storage since network keeps growing.
Local system setup
You need to setup node ansible in your local machine. Make sure you have ssh access to the remote machine. Your machine should have Python3.x installed.
1. Install ansible in you system using this command `pip3 install ansible`.
2. After installation check `ansible — version` to make sure ansible is installed properly.
3. Clone the https://github.com/maticnetwork/node-ansible
repo
4. Edit the inventory.yml
file and insert your remote server IP(s) in the `host`section. Add port with the IP if necessary.

5. You can remove the private_key_file line if you have ssh key setup in ansible.cfg
file.

6. Update ansible_user in group_vars/all file if you have any other user access in server. Default user is ubuntu. `ansible_user: ubuntu`
7. To check if setup is completed, run command `ansible sentry -m ping` inside the repo in terminal.
8. If it gives success output, you can setup full node in remote server by following command from the local machine inside the node ansible repo.
ansible-playbook -l sentry playbooks/network.yml — extra-var=”bor_branch=v0.2.16 heimdall_branch=v0.2.11 network_version=testnet-v4 node_type=sentry/sentry heimdall_network=mumbai”
# For main net, network_version is
mainnet-v1
and heimdall_network ismainnet
# For test net, network_version istestnet-v4
and heimdall_network ismumbai
9. If you ran into any issue during this setup run cleanup command and again run above setup command.ansible-playbook -l sentry playbooks/clean.yml
Updates in remote server
There are few things you need to update in your remote server.
Once you successfully run above command, you can find folders like .heimdalld, .bor, heimdall, bor etc in root of remote server.
Open file ~/.heimdalld/config/config.toml and update followingmoniker=<enter unique identifier>
eg: moniker=my-polygon-node
For mainnet:seeds="f4f605d60b8ffaaf15240564e58a81103510631c@159.203.9.164:26656,4fb1bc820088764a564d4f66bba1963d47d82329@44.232.55.71:26656,2eadba4be3ce47ac8db0a3538cb923b57b41c927@35.199.4.13:26656,3b23b20017a6f348d329c102ddc0088f0a10a444@35.221.13.28:26656,25f5f65a09c56e9f1d2d90618aa70cd358aa68da@35.230.116.151:26656"
For testnet:seeds="4cd60c1d76e44b05f7dfd8bab3f447b119e87042@54.147.31.250:26656"
Open file ~/.heimdalld/config/heimdall-config.toml and update followingeth_rpc_url =<insert Infura or any full node RPC URL to Ethereum>
It can be your desired domain name for RPC or any other RPC url.
Open file ~/node/bor/start.sh and add following for mainnet. — bootnodes “enode://0cb82b395094ee4a2915e9714894627de9ed8498fb881cec6db7c65e8b9a5bd7f2f25cc84e71e89d0947e51c76e85d0847de848c7782b13c0255247a6758178c@44.232.55.71:30303,enode://88116f4295f5a31538ae409e4d44ad40d22e44ee9342869e7d68bdec55b0f83c1530355ce8b41fbec0928a7d75a5745d528450d30aec92066ab6ba1ee351d710@159.203.9.164:30303”
For testnet: — bootnodes “enode://320553cda00dfc003f499a3ce9598029f364fbb3ed1222fdc20a94d97dcc4d8ba0cd0bfa996579dcc6d17a534741fb0a5da303a90579431259150de66b597251@54.147.31.250:30303”
After above updates, you can actually run services to start your own custom blockchain node. But blockchain will start from 0 block and you need to sync all blocks till today which will take massive amount of time. So to sync up the chain in short time we will use snapshots of the chain.
If you want to try how it works without using snapshots, follow these process. You can quit at any time. I recommend using snapshots though. You can skip to Downloading Snapshots
section and come back here later.
- Starting heimdall service:
sudo service heimdalld start
- Starting heimdall rest server:
sudo service heimdalld-rest-server start
- Starting bor service:
sudo service bor start
Before starting bor service, your heimdall must be synced completely, so that you won’t stuck in any errors.
To check if Heimdall is synced,
- On the remote machine/VM, run
curl localhost:26657/status
- In the output,
catching_up
value should befalse
Check logs of each service :
Heimdall:journalctl -u heimdalld.service -f
Heimdall Rest Server:journalctl -u heimdalld-rest-server.service -f
Bor:journalctl -u bor.service -f
Downloading snapshots
I am sure you do not want to stuck weeks to sync heimdall as well as bor. So let’s proceed with how to use snapshots.
- Goto url:
https://snapshots.matic.today
You will find snapshots for testnet as well as mainnet. You need to download heimdall and bor snapshot for your desired network. You can download heimdall and complete its sync up first and later continue with bor because it will take huge storage.
You can download it from remote server:wget -c <snapshot url>
You can also run it in background with command :wget -bqc <snapshot url>
- Once heimdall snapshot download is completed, extract it inside the heimdall data folder
tar -xzvf <downloaded snapshot> -C ~/.heimdalld/data/
You can also run it in background using nohup.
It will take quite a time. Keep checking if it is completed. Once it is completely extracted, you can delete snapshot file to empty storage. - Once it is completed, run heimdall and heimdall rest service
sudo service heimdalld start
If these services are already running, stop them first and start.
sudo service heimdalld-rest-server start
Now keep checking the status of heimdall service if the sync up is completed or not.
Once the value forcatching_up is false
, then you can continue with bor service. - Download latest bor snapshot from the url
https://snapshots.matic.today
Run :wget -c <snapshot url>
Extract the downloaded snapshot to bor data folder:tar -xzvf <snapshot url> -C ~/.bor/data/bor/chaindata
- It will take a while to complete extraction. Run bor service after the file is completely extracted:
sudo service bor start
It will then continue syncing up bor from the last block in snapshot.
To check if bor is synced, run it in remote server terminal:bor attach ~/.bor/data/bor.ipc
You can check for currentBlock and highestBlock by command: eth.syncing
Check currentBlock and highestBlock to see the difference. The difference will keep lowering as syncing process is running. If eth.syncing
gives false or undefined or if the difference is 0, then bor is all synced up.
These services should keep running to sync your node up to date.
Set up RPC domain with nginx
Now since heimdall and bor services are up and syncing, you are all good to go for setting up your RPC. You can now setup domain with nginx and also setup https with lets encrypt.
Check for connection
After your domain is set up, you can check connection with following command:curl -H “Content-Type: application/json” -d ‘{“id”:1, “jsonrpc”:”2.0", “method”: “eth_syncing”,”params”: []}’ your-rpc-url
If it returns , {“jsonrpc”:”2.0",”id”:1,”result”:false}
, then it is synced up and can be accessed with the rpc url.
You can now add your rpc url with related chain id in metamask and continue your transactions.
Please comment if you have any problems encountered when setting up the node.
Official Polygon Documentation: https://docs.polygon.technology/docs/develop/network-details/full-node-deployment/