This repository contains scripts for building, testing, and deploying the XDC checkpoint smart contract. Follow the guide below to get started.
Ensure you have Node.js version 20 or higher installed on your system.
-
Install Dependencies Install the necessary dependencies using yarn:
yarn
-
Testing Compile and test the contract using the following commands:
npx hardhat test
We recommend setting up the contract in a Python virtual environment since it utilizes the web3 library adapted for XDC. Before beginning, carry out these two steps:
-
Configuration
Complete the fields in
deployment.config.json
:subnet
: subnet deploy config :gap
: GAP block number on the public chainepoch
: Blocks per epoch on the public chaingsbn
: gap start block number, gap block required
parentnet
: Subnet deploy config :epoch
: Blocks per epoch on the public chainv2esbn
: V2 epoch start block number, epoch block required
Configure your network in
network.config.json
:xdcparentnet
: xdcparentnet RPC URLxdcsubnet
: xdcsubnet RPC URL
-
Environment Variables
Create a
.env
file containing a valid account private key (refer to.env.sample
for an example).
How to Obtain gsbn in the Subnet
The gap block in the subnet follows a regular pattern. By adding 451 to each multiple of 900, you get the GSBN. For example, 451, 1351, etc.
How to Obtain v2esbn in the Parentnet
The epoch number in the parentnet is unpredictable, but you can obtain the latest epoch number using the following command:
curl --location '${parentnet}' \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"method": "XDPoS_getMissedRoundsInEpochByBlockNum",
"params": [],
"id": 1
}'
Deploy the contract and obtain the deployed contract address as follows:
-
Full Checkpoint Deployment
npx hardhat run scripts/FullCheckpointDeploy.js --network xdcparentnet
-
Lite Checkpoint Deployment
npx hardhat run scripts/LiteCheckpointDeploy.js --network xdcparentnet
-
Reverse Full Checkpoint Deployment
npx hardhat run scripts/ReverseFullCheckpointDeploy.js --network xdcsubnet
For further assistance or to execute other operations, utilize the commands below:
npx hardhat accounts
npx hardhat compile
npx hardhat clean
npx hardhat test
npx hardhat node
npx hardhat help
REPORT_GAS=true npx hardhat test
npx prettier '**/*.{js,json,sol,md}' --check
npx prettier '**/*.{js,json,sol,md}' --write
npx solhint 'contracts/**/*.sol'
npx solhint 'contracts/**/*.sol' --fix
To upgrade the module, follow these steps:
-
Configuration
Complete the fields in
upgrade.config.json
:proxyGateway
: The admin contract managing all proxy contracts.
-
ProxyGateway Deployment
If you don't have a proxyGateway contract, deploy yours using:
npx hardhat run scripts/proxy/ProxyGatewayDeploy.js --network xdcparentnet
-
Upgrading
Upgrade the contract using:
npx hardhat run scripts/proxy/UpgradeCSC.js --network xdcparentnet
Because the node might modify the value of certThreshold
based on the configuration file, when the node makes such modifications, the certThreshold
in the CSC needs to be hardcoded and upgraded accordingly.