X Layer is now available on the Mainnet and Testnet for developers to launch smart contracts, execute transactions, and experiment with the network. This tutorial extends the exploration by allowing developers to launch their own node on the Public network. Before we begin, this document is fairly technical and requires prior exposure to Docker and CLI. Post spinning up your ZKNode instance, you will be able to run the Synchronizer and utilize the JSON-RPC interface.
This tutorial assumes that you have docker-compose already installed. If you need any help with the installation, please check the official docker-compose installation guide.
Here is a list of crucial network components that are required before you can run the ZKNode:
Let’s set up each of the above components!
The Ethereum RPC Node is the first component to be deployed because ZKNode needs to synchronize blocks and transactions on layer 1. You can invoke the ETH RPC (Mainnet: Ethereum OR Testnet: Sepolia) service through any of the following methods:
Once the layer 1 RPC component is complete, we can start the ZKNode setup. This is the most straightforward way to run a ZKNode and it’s fine for most use cases. Furthermore, this method is purely subjective and feel free to run this software in a different manner. For example, Docker is not required, you could simply use the Go binaries directly. Let’s start setting up our ZKNode:
mkdir -p ./xlayer-node && cd ./xlayer-node
# mainnet
curl -fsSL https://raw.githubusercontent.com/okx/Deploy/main/setup/zknode/run_xlayer_mainnet.sh | bash -s init && cp ./mainnet/example.env ./mainnet/.env
# testnet
curl -fsSL https://raw.githubusercontent.com/okx/Deploy/main/setup/zknode/run_xlayer_testnet.sh | bash -s init && cp ./testnet/example.env ./testnet/.env
# mainnet
vim ./mainnet/.env
# testnet
vim ./testnet/.env
# URL of a JSON RPC for Ethereum mainnet or Sepolia testnet
XLAYER_NODE_ETHERMAN_URL = "http://your.L1node.url"
# PATH WHERE THE STATEDB POSTGRES CONTAINER WILL STORE PERSISTENT DATA
XLAYER_NODE_STATEDB_DATA_DIR = "./xlayer_mainnet_data/statedb" # OR ./xlayer_testnet_datastatedb/ for testnet
# PATH WHERE THE POOLDB POSTGRES CONTAINER WILL STORE PERSISTENT DATA #
XLAYER_NODE_POOLDB_DATA_DIR = "./xlayer_mainnet_data/pooldb" # OR ./xlayer_testnet_data/pooldb/ for testnet
# mainnet
./run_xlayer_mainnet.sh restore
# testnet
./run_xlayer_testnet.sh restore
Use the below command to start the ZKNode instance:
# mainnet
./run_xlayer_mainnet.sh start
# testnet
./run_xlayer_testnet.sh start
docker ps -a
You will see a list of the following containers :
You should now be able to run queries to the JSON-RPC endpoint at http://localhost:8545. Run the following query to get the most recently synchronized layer 2 block; if you call it every few seconds, you should see the number grow:
curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":83}' http://localhost:8545
Use the below command to stop the ZKNode instance:
# mainnet
./run_xlayer_mainnet.sh stop
# testnet
./run_xlayer_testnet.sh stop
Use the below command to stop the ZKNode instance:
# mainnet
./run_xlayer_mainnet.sh restart
# testnet
./run_xlayer_testnet.sh restart
To update the ZKNode software, run the below command, and the file ./mainnet(or testnet)/.env
will be retained, the other config will be deleted.
# mainnet
./run_xlayer_mainnet.sh update
# testnet
./run_xlayer_testnet.sh update
./mainnet(testnet)/docker-compose.yml
.docker ps -a
docker logs <cointainer_name>
docker stop xlayer-sync
docker stop xlayer-rpc
PGPASSWORD=state_password psql -h 127.0.0.1 -p 5432 -d state_db -U state_user
SELECT max(batch_num) FROM state.verified_batch;
# Use the batch_num above to perform the resync from a specific batch (e.g. 330000):
delete from state.block where block_num >= 5517146;
delete from state.batch where batch_num >= 329992;