Complete the code to import the Hardhat network helpers for mainnet forking.
const { [1] } = require('hardhat');We import network from Hardhat to configure mainnet forking.
Complete the code to set the mainnet fork URL in the Hardhat config.
module.exports = {
networks: {
hardhat: {
forking: {
url: '[1]'
}
}
}
};The mainnet fork URL must point to the Ethereum mainnet RPC endpoint, such as Infura's mainnet URL.
Fix the error in the code to reset the Hardhat network fork block number.
await network.provider.request({
method: 'hardhat_reset',
params: [{
forking: {
jsonRpcUrl: '[1]',
blockNumber: 12345678
}
}]
});The jsonRpcUrl must be the mainnet RPC URL to reset the fork correctly.
Fill both blanks to create a forked provider and get the block number.
const provider = new ethers.providers.JsonRpcProvider([1]); const blockNumber = await provider.getBlockNumber(); console.log('Forked block number:', [2]);
Use the Hardhat RPC URL to create the provider for the forked network and then print the block number variable.
Fill all three blanks to advance the forked network to a specific block and get its timestamp.
await network.provider.request({
method: '[1]',
params: [{
blockNumber: [2]
}]
});
const block = await ethers.provider.getBlock([3]);
console.log('Block timestamp:', block.timestamp);The method hardhat_setBlockNumber advances the fork to the given block number, which is then used to get the block timestamp.