2

I'm using hardhat to fork the polygon mainnet by - npx hardhat node --fork <ALCHEMY RPC ENDPOINT>

now i want to test on this local network. what is the command? npx hardhat test is not working.

3 Answers 3

2

You can configure hardhat forking in the hardhat.config file

 networks: {
        hardhat: {
          forking: {
            // eslint-disable-next-line
            enabled: true,
            url: `https://eth-mainnet.alchemyapi.io/v2/${process.env.ALCHEMY_API_KEY}`,
      }
1
  • Note that with this config, you don't need to pass --fork anymore, you can simply run: npx hardhat node
    – Didier
    Sep 2, 2022 at 16:20
1

You need to set your mainnet fork in hardhat.config.js

module.exports = {
  solidity: "0.8.9",
  networks: {
    fork: {
      url: "<ALCHEMY RPC ENDPOINT>",
    },
  }
}

And you can just type npx hardhat test --network fork to run the test in your mainnet fork.

0

Set the hardhat.config.js in the following way

module.exports = {
  solidity: "0.8.9",
  networks: {
    fork: {
      url: "<ALCHEMY RPC ENDPOINT>",
    },
  }
}

Now in one terminal, run the command npx hardhat node

In other terminal, run the command npx hardhat test ./{Your_file_location} --network localhost

After this in the terminal where you had run npx hardhat node, you'll see the calls made over the network like - contract deployment, function calls, gas estimations, etc.

I have attached the picture for your reference. This confirms that your mainnet fork worked!! enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.