I saw that it is possible to test with Hardhat on a forked chain, via the config file.

Is it possible to do it on the test file instead? In a beforeEach, maybe.

I only want some of my tests to run on a fork, while the majority should just run on the normal test network.

1 Answer 1



just change your network (add this with your api key to the before each):

await hre.network.provider.request({
      method: "hardhat_reset",
      params: [{forking: {
            jsonRpcUrl: "https://eth-mainnet.alchemyapi.io/v2/xxxxxx",

Your Answer

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

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