# Forking with hardhat

By [N00b21337](https://paragraph.com/@n00b21337) · 2023-08-07

---

To fork a network in hardhat you need to change config that adds this line to your networks

      networks: {
        hardhat: { 
            forking: {
            enabled: true,
            url: 'https://rpc.gnosischain.com',
            blockNumber: 29279000,
          },
    ....
    

  
With that, when you run hardhat node or hardhat test you will have your local node running at snapshot of whatever chain **url** rpc you put into config.  
  
This will give you different output when running tests

        it('return data for forked network, async function () {
          console.log(await getBlockNumber());
          console.log(network.config.forking.enabled);
          await mineNBlocks(150);
          console.log(await getBlockNumber());
        });
    

  
This will output info about forked network and you should be able to run tests on forked network state.  
  
Another option is to have tests setup with this snippet and run them on forked network so you can combined local tests and forked network tests.  
  
Put this into before block

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

---

*Originally published on [N00b21337](https://paragraph.com/@n00b21337/forking-with-hardhat)*
