Closed MarcBickel closed 4 months ago
I also encountered it, it should be a problem with v2.22.3, I downgraded the version to v2.22.2 and it ran normally.
I still get it with v2.22.2, forking the same network as above.
I still get it with v2.22.2, forking the same network as above.
Sorry I saw it wrong, I reverted to v2.19.4
Can confirm this error goes away with v2.19.4, but I am relying on features introduced later (and get other errors), so can't really use that version. Thanks for the input though!
As additional input: my script works with anvil running the local fork, so error should be on the node task side
You can try to roll back to the previous version from v2.22.3
Hi, I can't reproduce this. I'm forking sepolia and running a call with some random ERC-20:
const blockNumber = await ethers.provider.getBlockNumber()
const mockDai = await ethers.getContractAt(["function totalSupply() public view returns(uint256)"], "0xd6a17186e7bde277ad70e5d5c99d042acf30990c")
console.log(await mockDai.totalSupply())
console.log(await mockDai.totalSupply({blockTag: blockNumber - 10}))
Could someone give us a minimal reproducible example?
Steps to reproduce:
Have a hardhat config file
defaultNetwork: "arbitrumSepolia",
solidity: {
version: "0.8.25",
settings: {
viaIR: true,
optimizer: {
enabled: true,
runs: 10,
details: {
yulDetails: {
optimizerSteps: "u",
},
},
},
evmVersion: "cancun",
},
}
networks: {
hardhat: {
forking: {
enabled: true,
url: `https://arb-sepolia.g.alchemy.com/v2/<APIKEY>`,
},
}
Run npx hardhat node --fork https://arb-sepolia.g.alchemy.com/v2/<APIKEY>
Run npx hardhat run --network localhost scripts/testMultiContract.ts
(or any script).
The first lines of the script are (after getting the accounts) as follows. Most likely hangs with any eth_call though.
const currencyContract = "0xB28bbA1a16eB2aB0B0E4396f90BFbC04B6e344dC";
const USDT = await ethers.getContractAt("TestnetERC20", currencyContract);
const currencyDecimals = Number(await USDT.decimals());
Get an error
ProviderError: No known hardfork for execution on historical block 44273914 (relative to fork block number 44273914). The node was not configured with a hardfork activation history.
at HttpProvider.request (/Users/marc/Documents/Fume-Protocol/node_modules/hardhat/src/internal/core/providers/http.ts:90:21)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async staticCallResult (/Users/marc/Documents/Fume-Protocol/node_modules/ethers/src.ts/contract/contract.ts:337:22)
at async staticCall (/Users/marc/Documents/Fume-Protocol/node_modules/ethers/src.ts/contract/contract.ts:303:24)
at async Proxy.decimals (/Users/marc/Documents/Fume-Protocol/node_modules/ethers/src.ts/contract/contract.ts:351:41)
at async main (/Users/marc/Documents/Fume-Protocol/scripts/testMultiContract.ts:19:39)
I downgraded the version to v2.20.1 and it worked on optimistic network
"devDependencies": {
"@nomicfoundation/hardhat-toolbox": "^4.0.0",
"hardhat": "^2.20.1"
}
Testcase code :
import hre from "hardhat";
//USDC 合约地址
const USDC_ADDRESS = "0x0b2c639c533813f4aa9d7837caf62653d097ff85";
//USDC ABI
const USDC_ABI = ["function totalSupply() public view returns (uint)"];
describe("Optimistic USDC", function () {
describe("Balance", function () {
it("Get usdc balance by address", async function () {
const usdcToken = await hre.ethers.getContractAt(USDC_ABI, USDC_ADDRESS);
const block = await hre.ethers.provider.getBlockNumber();
console.log("Optimistic Block Number", block);
//获取 USDT 总发行量
const totalSupply = await usdcToken.totalSupply();
console.log("Optimistic USDC totalSupply", hre.ethers.formatUnits(totalSupply, 6));
});
});
});
Run command:
fork:
npx hardhat node --fork https://opt-mainnet.g.alchemy.com/v2/...
run:
npx hardhat test --network localhost
Result:
Optimistic USDC
Balance
Optimistic Block Number 120288014
Optimistic USDC totalSupply 169377140.604314
✔ Get usdc balance by address (3721ms)
1 passing (4s)
@noodlespan I can confirm this fixes the error as well with v2.20.1
. I get strange other errors in my script afterwards, but that's most likely on me (reverts for unkown reason, works with anvil). Most likely bug in the rust rework then
@fvictorio Is that enough or do you need more info?
Confirmed and important, thanks!
I hope we can fix this soon, but in the meantime: a workaround seems to be to immediately mine a block after starting the node. For example, adding this at the beginning of the script:
import * as helpers from "@nomicfoundation/hardhat-network-helpers";
await helpers.mine()
// rest of the script
@fvictorio Thanks for the workaround, can confirm this does fix the problem, at least temporally 👍
(I put the await helpers.mine()
in main()
if someone else also needs the workaround)
I hope we can fix this soon, but in the meantime: a workaround seems to be to immediately mine a block after starting the node. For example, adding this at the beginning of the script:
import * as helpers from "@nomicfoundation/hardhat-network-helpers"; await helpers.mine() // rest of the script
I am using 2.22.5.
Didnt downgrade.
used the code shared above. It resolved my issue.
I am still getting this error on the latest version. Is it supposed to be solved?
Hardhat version: "^2.22.8"
@bytes0xcr6 we fixed it for some chains (Optimism and Arbitrum mainnets and testnets). This will continue to be an issue for "unknown" chains. The workarounds are:
We are going to fix the underlying issue so that these workarounds are not necessary, but I don't have an estimation of when that will happen.
I still get it with v2.22.2, forking the same network as above.
Sorry I saw it wrong, I reverted to v2.19.4
I had the same problem. When I reverted hardhat to v2.19.4, everything worked. Thank you!
Still getting this issue on "^2.22.5" mine()
worked great thank you @fvictorio
@Quazia which chain are you using? Zora?
@bytes0xcr6 we fixed it for some chains (Optimism and Arbitrum mainnets and testnets). This will continue to be an issue for "unknown" chains. The workarounds are:
- Add a hardfork history for that chain (docs)
- Mine a block before making any calls (an ugly workaround but it works)
We are going to fix the underlying issue so that these workarounds are not necessary, but I don't have an estimation of when that will happen.
I got the same issue with Blast chain. I added the hardForkHistory in my hardhat.config.js file :
hardhat: {
forking: {
url: `https://rpc.blast.io`,
blockNumber: 9192511
},
chainId: 0x13e31,
chains: {
0x13e31: {
hardforkHistory: {
berlin: 1000000,
london: 2000000,
},
}
}
},
Version of Hardhat
2.22.3
What happened?
Forked arbitrum sepolia with
npx hardhat node
, when trying to run a typescript script that calls any function on-chain (even simple view function), I get the errorProviderError: No known hardfork for execution on historical block 42324641 (relative to fork block number 42324641). The node was not configured with a hardfork activation history.
The block number is the block at which the chain has been forked I believe (didn't specify so should be
latest
).Minimal reproduction steps
Fork arbitrum sepolia with
npx hardhat node
with an alchemy endpoint.Search terms
No response