Polygon

Set up your Polygon Mainnet or Testnet (Mumbai) node.

Prerequisites

Install required dependencies

In order to build the polygon node, you first need to install all of the required dependencies.

1. Update and install build-essential

Terminal window
sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get install -y build-essential

2. Install golang

Install the latest version of golang.

Install the Polygon node

Polygon node consists of 2 layers, Heimdall and Bor. Heimdall is a fork of tendermint and runs in parallel to the Ethereum network, monitoring contracts, and Bor is a fork of go-Ethereum and producing blocks shuffled by Heimdall nodes. You need to install and run both binaries in the correct order, as explained in the following steps.

Install the latest versions for the network accordingly heimdall latest release tag and bor latest release tag

Terminal window
# These are examples - check their docs and release page to opt for the right version
HEIMDALL_RELEASE=v1.0.5
BOR_RELEASE=v1.2.8

1. Install Heimdall

Terminal window
https://raw.githubusercontent.com/maticnetwork/install/main/heimdall.sh |
bash -s -- $HEIMDALL_RELEASE mainnet sentry
Terminal window
https://raw.githubusercontent.com/maticnetwork/install/main/heimdall.sh |
bash -s -- $HEIMDALL_RELEASE amoy sentry

2. Install Bor

Terminal window
https://raw.githubusercontent.com/maticnetwork/install/main/bor.sh | bash -s
-- $BOR_RELEASE mainnet sentry
Terminal window
https://raw.githubusercontent.com/maticnetwork/install/main/bor.sh | bash -s
-- $BOR_RELEASE amoy sentry

Check Versions

Terminal window
heimdalld version --long
bor version

Setup and configure node

1. Configure Bor seeds

Terminal window
/var/lib/bor/config.toml sed -i 's|.*bootnodes =.*| bootnodes =
["enode://b8f1cc9c5d4403703fbf377116469667d2b1823c0daf16b7250aa576bacf399e42c3930ccfcb02c5df6879565a2b8931335565f0e8d3f8e72385ecf4a4bf160a@3.36.224.80:30303",
"enode://8729e0c825f3d9cad382555f3e46dcff21af323e89025a0e6312df541f4a9e73abfa562d64906f5e59c51fe6f0501b3e61b07979606c56329c020ed739910759@54.194.245.5:30303"]|g'
/var/lib/bor/config.toml chown bor /var/lib/bor
Terminal window
testnet since they’ve already been included at genesis.

2. Update service config user permission

Terminal window
sed -i 's/User=heimdall/User=$USER/g' /lib/systemd/system/heimdalld.service
sed -i 's/User=bor/User=$$USER/g' /lib/systemd/system/bor.service

3. Open port to public

Open the /var/lib/bor/config.toml and edit host address under jsonrpc.http

Terminal window
[jsonrpc]
ipcpath = "/var/lib/bor/bor.ipc"
# ipcdisable = false
# gascap = 50000000
# evmtimeout = "5s"
# txfeecap = 5.0
# allow-unprotected-txs = false
# enabledeprecatedpersonal = false
[jsonrpc.http]
enabled = true
port = 8545
host = "0.0.0.0" # change this to "0.0.0.0" from "127.0.0.1"
api = ["eth", "net", "web3", "txpool", "bor"]
vhosts = ["*"]
corsdomain = ["*"]

Sync from snapshot

Bor

Terminal window
mkdir "/var/lib/bor/chaindata"
Terminal window
bash -s -- --network mainnet --client bor --extract-dir
/var/lib/bor/chaindata --validate-checksum true
Terminal window
bash -s -- --network amoy --client bor --extract-dir /var/lib/bor/chaindata
--validate-checksum true

Heimdall

Terminal window
bash -s -- --network mainnet --client heimdall --extract-dir
/var/lib/heimdall/data --validate-checksum true
Terminal window
bash -s -- --network amoy --client heimdall --extract-dir
/var/lib/heimdall/data --validate-checksum true

Start the services

Terminal window
sudo service heimdalld start
sudo service bor start

Check logs

Terminal window
journalctl -u heimdalld.service -f -n 100 -o cat
journalctl -u heimdalld-rest-server.service -f -n 100 -o cat
journalctl -u bor.service -f -n 100 -o cat

Verify RPC

Once your Bor node is fully synced, you can run a cURL request to see the status of your node:

Terminal window
curl -H "Content-Type: application/json" -d '{"id":1, "jsonrpc":"2.0", "method": "eth_syncing", "params":[]}' localhost:8545

If the node is successfully synced, the output from above will print {"jsonrpc":"2.0","id":1,"result":false}

Configure vald

In order for vald to connect to your node, your rpc_addr should be exposed in vald’s config.toml

Terminal window
start-with-bridge = true
Terminal window
start-with-bridge = true

Edit on GitHub