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.
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communityYou 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}`,
}
--fork
anymore, you can simply run: npx hardhat node
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.
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!!