0
0
Blockchain / Solidityprogramming~10 mins

Fork testing (mainnet fork) in Blockchain / Solidity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Hardhat network helpers for mainnet forking.

Blockchain / Solidity
const { [1] } = require('hardhat');
Drag options to blanks, or click blank then click option'
Anetwork
Bethers
Cweb3
Dfs
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'ethers' instead of 'network'.
Using 'web3' which is not part of Hardhat by default.
2fill in blank
medium

Complete the code to set the mainnet fork URL in the Hardhat config.

Blockchain / Solidity
module.exports = {
  networks: {
    hardhat: {
      forking: {
        url: '[1]'
      }
    }
  }
};
Drag options to blanks, or click blank then click option'
A'https://mainnet.infura.io/v3/YOUR-PROJECT-ID'
B'http://localhost:8545'
C'https://kovan.infura.io/v3/YOUR-PROJECT-ID'
D'https://rinkeby.infura.io/v3/YOUR-PROJECT-ID'
Attempts:
3 left
💡 Hint
Common Mistakes
Using testnet URLs like Rinkeby or Kovan.
Using localhost URL which is not a mainnet fork.
3fill in blank
hard

Fix the error in the code to reset the Hardhat network fork block number.

Blockchain / Solidity
await network.provider.request({
  method: 'hardhat_reset',
  params: [{
    forking: {
      jsonRpcUrl: '[1]',
      blockNumber: 12345678
    }
  }]
});
Drag options to blanks, or click blank then click option'
A'https://rinkeby.infura.io/v3/YOUR-PROJECT-ID'
B'https://kovan.infura.io/v3/YOUR-PROJECT-ID'
C'https://mainnet.infura.io/v3/YOUR-PROJECT-ID'
D'http://localhost:8545'
Attempts:
3 left
💡 Hint
Common Mistakes
Using testnet URLs causes fork reset to fail.
Using localhost URL does not reset the mainnet fork.
4fill in blank
hard

Fill both blanks to create a forked provider and get the block number.

Blockchain / Solidity
const provider = new ethers.providers.JsonRpcProvider([1]);
const blockNumber = await provider.getBlockNumber();
console.log('Forked block number:', [2]);
Drag options to blanks, or click blank then click option'
A'http://localhost:8545'
BblockNumber
C'https://mainnet.infura.io/v3/YOUR-PROJECT-ID'
Dprovider
Attempts:
3 left
💡 Hint
Common Mistakes
Using mainnet URL instead of localhost URL.
Printing the provider object instead of the block number.
5fill in blank
hard

Fill all three blanks to advance the forked network to a specific block and get its timestamp.

Blockchain / Solidity
await network.provider.request({
  method: '[1]',
  params: [{
    blockNumber: [2]
  }]
});
const block = await ethers.provider.getBlock([3]);
console.log('Block timestamp:', block.timestamp);
Drag options to blanks, or click blank then click option'
Ahardhat_mine
Bhardhat_reset
C12345678
Dhardhat_setBlockNumber
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method names like 'hardhat_mine'.
Using different block numbers in method and getBlock call.