Skip to content

Commit 9e8b6eb

Browse files
authored
Merge pull request #12 from lidofinance/feat/dont-set-chainid
Add option to don't set chainId
2 parents 39f88d6 + 739cecb commit 9e8b6eb

File tree

8 files changed

+31
-5
lines changed

8 files changed

+31
-5
lines changed

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
INFURA_TOKEN=
22
ALCHEMY_TOKEN=
3-
RPC_URL=
3+
RPC_URL=
4+
DONT_SENT_CHAIN_ID=

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ If you don't need testing ant holesky use `-holesky-fork` node, for example:
2929
```bash
3030
docker run -e ETH_RPC_URL=your_url -p 8545:8545 -it --rm ghcr.io/lidofinance/hardhat-node:2.22.18.1-holesky-fork
3131
```
32+
33+
### Forking fork chainId issue
34+
35+
There might an issue when forking hardhat node with a hardhat node which causes an error like:
36+
37+
```
38+
The response reported error `-32000`: `header not found`. (optional data: None). Request: {"jsonrpc":"2.0","method":"eth_getBalance","params":["0x61097ba76cd906d2ba4fd106e757f7eb455fc295","0x15062e6"],"id":275}
39+
```
40+
41+
To fix this `chainId` must not be set in the forked node. To do so set `DONT_SENT_CHAIN_ID` env variable, e.g. `DONT_SENT_CHAIN_ID=1`.
42+
3243
### Updating hardhat version
3344

3445
- set the new version in package.json

hardhat.config.holesky-fork.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ const config: HardhatUserConfig = {
99
solidity: "0.8.23",
1010
networks: {
1111
hardhat: {
12+
...networks.maybeChainIdConfig(17000),
1213
initialBaseFeePerGas: 0,
1314
accounts: {
1415
count: 10,
1516
},
16-
chainId: 17000,
1717
forking: {
1818
url: networks.rpcUrl("eth", "holesky"),
1919
},

hardhat.config.mainnet-fork-shanghai.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ const config: HardhatUserConfig = {
99
solidity: "0.8.23",
1010
networks: {
1111
hardhat: {
12+
...networks.maybeChainIdConfig(1),
1213
hardfork: "shanghai",
1314
initialBaseFeePerGas: 0,
1415
accounts: {
1516
count: 10,
1617
},
17-
chainId: 1,
1818
forking: {
1919
url: networks.rpcUrl("eth", "mainnet"),
2020
},

hardhat.config.mainnet-fork.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ const config: HardhatUserConfig = {
99
solidity: "0.8.23",
1010
networks: {
1111
hardhat: {
12+
...networks.maybeChainIdConfig(1),
1213
initialBaseFeePerGas: 0,
1314
accounts: {
1415
count: 10,
1516
},
16-
chainId: 1,
1717
forking: {
1818
url: networks.rpcUrl("eth", "mainnet"),
1919
},

hardhat.config.mainnet-scratch.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import "dotenv/config";
22
import { HardhatUserConfig } from "hardhat/config";
33
import "@nomicfoundation/hardhat-ethers";
4+
import networks from "./src/networks";
45

56
const config: HardhatUserConfig = {
67
solidity: "0.8.23",
78
networks: {
89
hardhat: {
10+
...networks.maybeChainIdConfig(1),
911
initialBaseFeePerGas: 0,
1012
accounts: {
1113
count: 10,
1214
},
13-
chainId: 1,
1415
},
1516
},
1617
};

src/env.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ function ALCHEMY_TOKEN() {
3030
return process.env["ALCHEMY_TOKEN"];
3131
}
3232

33+
function DONT_SET_CHAIN_ID() {
34+
return Boolean(process.env["DONT_SET_CHAIN_ID"]);
35+
}
36+
3337
export default {
3438
ETH_RPC_URL,
3539
ARB_RPC_URL,
@@ -39,4 +43,5 @@ export default {
3943
LOCAL_ARB_RPC_URL,
4044
LOCAL_OPT_RPC_URL,
4145
ALCHEMY_TOKEN,
46+
DONT_SET_CHAIN_ID,
4247
};

src/networks.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ function rpcUrl(chainName: ChainName) {
2626
if (chainName === "opt") return env.OPT_RPC_URL();
2727
}
2828

29+
function maybeChainIdConfig(chainId: number) {
30+
if (env.DONT_SET_CHAIN_ID()) {
31+
return { };
32+
}
33+
return { chainId };
34+
}
35+
2936
function infuraUrl(chainName: ChainName, networkName: NetworkName) {
3037
const infuraToken = env.INFURA_TOKEN();
3138
const infuraNetworkDomain =
@@ -46,4 +53,5 @@ function alchemyUrl(chainName: ChainName, networkName: NetworkName) {
4653

4754
export default {
4855
rpcUrl: url,
56+
maybeChainIdConfig,
4957
};

0 commit comments

Comments
 (0)