Effortless Installation of Polygon zkEVM Node

Anubhav Chaturvedi
5 min readMar 9, 2024

As the blockchain ecosystem evolves, Polygon zkEVM emerges as a promising solution, offering scalability, security, and interoperability. However, setting up a Polygon zkEVM node traditionally involves numerous steps, potentially daunting for newcomers and seasoned developers alike.

In this guide, we’ll explore how Polygon zkEVM is simplifying the node installation process, streamlining the development journey for blockchain enthusiasts. Whether you’re a developer eager to dive into zk-rollups or a project manager seeking to integrate Polygon’s technology, this tutorial will serve as your comprehensive roadmap to effortlessly set up a Polygon zkEVM node.

Let’s embark on this journey together and unlock the potential of Polygon zkEVM with ease.

Create an Alchemy-Account:

To establish a connection between your node and our app (on the Ethereum Blockchain) it is mandatory to create an Alchemy account. Use the provided link to create an Alchemy account and follow the following steps in sequential order:

To create an account, you have the option of either signing up with your Google account or clicking “Sign up” to create a new one.

For creating new app ,You can choose to have the same name and description for your app, then simply click “Create App” after making your selections:

Opt for the free plan, skip the payment section, and proceed by clicking “Continue” twice. Now you should be able to see your app.

Access the “API Key” section and copy the URL from the HTTPS section:

Once you are ready with alchemy.com account, let’s configure the node.

Prerequisites:

Hardware:

  • A Linux-based OS (e.g., Ubuntu Server 22.04 LTS).
  • At least 16GB RAM with a 4-core CPU.
  • An AMD64 architecture system.

Miscellaneous requirements:

  • Alchemy key that we just created in the above steps.
  • ETHERSCAN_API_KEY: Etherscan API key

Preparations:

To continue, we can update the packages by running the following commands in the terminal.

sudo apt update && sudo apt upgrade -y

To install the required libraries, you can use the following command :

sudo apt install -y pkg-config curl git build-essential libssl-dev screen unzip docker.io

Install docker-compose with:

sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

To check the version of Docker Compose installed on your system, you can use the following command.

docker-compose --version

Node Installation and Configuration:

To set the variables ZKEVM_NET, ZKEVM_DIR, and ZKEVM_CONFIG_DIR, Add the below commands to .bashrc and execute “source ~/.bashrc” to apply the changes and ensure they take effect in your current shell session. These commands will set the values of the variables to the specified values.

export ZKEVM_NET=mainnet
export ZKEVM_DIR=./ZKEVM
export ZKEVM_CONFIG_DIR=./ZKEVM_CONFIG

To create the ZKEVM config folder, you can use the following command:

mkdir "$ZKEVM_CONFIG_DIR"

To download and extract the necessary files, you can use the following command:

curl -L https://github.com/0xPolygonHermez/zkevm-node/releases/latest/download/$ZKEVM_NET.zip > $ZKEVM_NET.zip && unzip -o $ZKEVM_NET.zip -d $ZKEVM_DIR && rm $ZKEVM_NET.zip

To copy the example.env file with the environment parameters, you can use the following command. This command uses the cp command to copy the example.env file from the path specified by $ZKEVM_DIR/$ZKEVM_NET/example.env to the destination path specified by $ZKEVM_CONFIG_DIR/.env. By enclosing the file paths in double quotes, it ensures that the command will properly handle any special characters or spaces in the paths. After running this command, the examplex file will be copied to the specified location as .env file within the $ZKEVM_CONFIG_DIR:

cp "$ZKEVM_DIR/$ZKEVM_NET/example.env" "$ZKEVM_CONFIG_DIR/.env"

To modify the example.env file according to your configurations, you can use your favorite text editor. This command will open the .env file located in the directory specified by $ZKEVM_CONFIG_DIR using nano as the text editor. It allows you to make changes to the file, update the configurations, and save the modifications. Feel free to replace nano with your preferred text editor if you have a different one:

nano $ZKEVM_CONFIG_DIR/.env

Replace the variables as following:

- ZKEVM_NODE_ETHERMAN_URL → Replace with your own link
- ZKEVM_NODE_STATEDB_DIR → Replace as shown below
- ZKEVM_NODE_POOLDB_DATA_DIR → Replace as shown below

… to exit, press CTRL+X and to save, press Y and then Enter.
Your .env should look like this.

ZKEVM_NETWORK = "mainnet"
# URL of a JSON RPC for Ethereum mainnet
ZKEVM_NODE_ETHERMAN_URL = "https://eth-mainnet.g.alchemy.com/v2/oCc33Pa9iOaHPtrYWMsdf9-Ex9A0sF0"
ZKEVM_NODE_STATEDB_DATA_DIR = "/home/ubuntu/.zkevm/data/statedb"
ZKEVM_NODE_POOLDB_DATA_DIR = "/home/ubuntu/.zkevm/data/pooldb"

Also change Etherman URL at: ZKEVM/mainnet/config/environments/mainnet/node.config.toml

Executing Your Node:

Use the following command to start the zkNode instance:

sudo docker-compose --env-file $ZKEVM_CONFIG_DIR/.env -f $ZKEVM_DIR/$ZKEVM_NET/docker-compose.yml up -d

output:

output

If you get an error like this in container zkevm-state-db, you need to edit docker-compose file at ZKEVM/mainnet/docker-compose.yml. change the commands for container zkevm-state-db as follow and try again.

ERROR
    command:
- "postgres"
- "-c"
- "shared_buffers=1GB"
- "-c"
- "max_connections=100"
- "-c"
- "config_file=/etc/postgresql.conf"

Once you have completed the setup, you can confirm the proper functioning of your node by checking your Alchemy account:

Alchemy App dashboard

Addressing the absence of entering our wallet address prompts questions regarding how rewards will be received. While the process remains uncertain presently, there is optimism that Polygon will furnish a command facilitating the connection between our node and wallet.

I hope this article was informative and provided you with the details you required. If you have any questions while reading the blog, message me on Instagram or LinkedIn. Special credits to my team member: Gaurav Kachariya

Thank You…

--

--

Anubhav Chaturvedi

Linux & DevOps Geek, Blockchain Developer ,Statistics & Data Nerd ,Solutions architect, passionate hands on instructor . High on Athletics and Travel