Background
Some developers have reported that testing the OKC mainnet with ganache-cli fork and hardhat fork often fails. This is because the RPC node of OKC mainnet does not keep the data of historical blocks, which causes the data request to fail and fork cannot be performed. Now I will introduce the correct way to fork OKC mainnet.
Instruction
Firstly: Do not use a regular RPC node to fork the OKC mainnet, please use a proprietary node: http://13.230.141.168:26659
Secondly: The node only keeps the historical blocks with the serial number of 10,000 and the last 1,000 blocks, so when specifying a block to fork, please make sure the block number meets the requirements, if not specify the block default fork the latest block.
For example, suppose the block number is N, N should satisfy the following conditions
You can use the block number that is an integer multiple of 10,000: N % 10000 = 0
You can use the block number of the last thousand blocks: latest - N < 1000
Note:
This node may experience block delays, etc. So it should only be used for fork testing and is not recommended for sending normal requests.
Example
The ganache fork command is as follows.
ganache-cli --fork http://13.230.141.168:26659@10910000 -u "0xeB196a61f9A1E35Bf5053b65AAA57c5541dcBa86"//Simulate the specified account
If you are using hardhat, add the following to hardhat.config.js to implement the mainnet fork.
module.exports = {
solidity: {
version: "0.8.0",
settings: {
optimizer: {
enabled: true,
runs: 200
}
}
},
networks: {
hardhat: {
forking: {
url: "http://13.230.141.168:26659"
// blockNumber: 10910000
}
}
}
};