It’s crucial that developers can thoroughly test the network for a developing blockchain technology like X Layer ZKEVM without putting users or themselves at unnecessary risk. Developers should be able to test their smart contracts, experiment with new code, and play around with the network on their local machines. X Layer ZKEVM has a local development environment setup for this reason. This tutorial will help you create a local single-node ZKEVM blockchain with no connections to external peers. It only exists on your local machine.
After completing this tutorial, you will have the following components running:
The tutorial for current version of the environment requires Foundryup
, go
, docker
and docker-compose
to be previously installed on your machine. If you don’t have these installed, check out the links provided below:
If you want to run a full-fledged ZKProver on your own, you’ll need at least 1TB of RAM. If you are unable to meet the Prover requirements, you can still run the zkNode.
Before starting the ZKEVM node setup, we need to clone the official ZKNode repository from xlayer-node Github.
# latest_version refers to https://github.com/okx/xlayer-node/releases
git clone -b latest_version https://github.com/okx/xlayer-node
cd xlayer-node
The xlayer-node
docker image must be built at least once and whenever the code is changed. If you haven’t already built the xlayer-node
image, you must run:
make build-docker
Certain commands on the xlayer-node
can interact with smart contracts, run specific components, create encryption files, and print debug information.
To interact with the binary program, we provide docker-compose
files and a Makefile
to spin up/down the various services and components, ensuring smooth local deployment and a better command line interface for developers.
The test/
directory contains scripts and files for developing and debugging. Change the working directory to test/
on your local machine.
cd test/
Now, run the ZKNode environment:
make run
To stop the ZKNode:
make stop
To restart the whole ZKNode environment:
make restart
The Synchronizer regularly pulls for network updates, mainly from Ethereum but also via the Trusted Sequencer’s broadcasting mechanism, in order to stay up-to-date. Unless otherwise specified in the setup, the Synchronizer’s default syncing rate is every 2 seconds. The Keystore file, used to store private keys, is normally required for running the Sequencer & Aggregator but not for a Synchronizer/RPC-setup.
It’s important to populate your local ZKEVM node with some data before you start testing out the network. The make run
command will execute the containers required to run the environment, but it will not execute anything else. Your local layer 2 network will be essentially empty.
The following scripts are available if you require sample data that has already been deployed to the network.
cast send --legacy --from 0x2ECF31eCe36ccaC2d3222A303b1409233ECBB225 --private-key 0xde3ca643a52f5543e84ba984c4419ff40dbabd0e483c31c1d09fee8168d68e38 --rpc-url http://127.0.0.1:8123 0xC949254d682D8c9ad5682521675b8F43b102aec4 --value 10ether
# To add some examples of transactions and smart contracts:
make deploy-sc
# To deploy a full Uniswap environment:
make deploy-uniswap
# To grant the OKB smart contract a set amount of tokens:
make run-approve-matic
To configure your MetaMask to use your local ZKEVM environment, follow these steps:
You can now interact with your local ZKEVM network and sign transactions from your MetaMask wallet.