NetworkNotFoundError: No network with chain id 9998 found. You can override the chain by passing it as a parameter to the client getter:
Describe the feature
hardhat.config.ts
// ztc
ztc: {
chainId: 9998,
url: "https://zitcoin.us",
accounts: [vars.get("PRIVATE_KEY")],
},
const [owner] = await hre.viem.getWalletClients();
const contract = await hre.viem.getContractAt(
"MyNFT",
vars.get("CONTRACT") as Address
);
const tx = await contract.write.mint([owner.account.address]);
console.log(tx);
How to solve the problem of not supporting other evm networks
Search terms
No response
Hardhat lets you specify alternate network configurations to connect to: https://hardhat.org/hardhat-runner/docs/config#networks-configuration
We have no experience with zitcoin, but the error indicates that on connection to the remote node at the url https://zitcoin.us, it got a failed repsonse when checking the chainId, or that the chainId did not match.
In fact, the chainId returned by the node is indeed 9998. How to solve it?
Hardhat lets you specify alternate network configurations to connect to: https://hardhat.org/hardhat-runner/docs/config#networks-configuration
We have no experience with
zitcoin, but the error indicates that on connection to the remote node at the urlhttps://zitcoin.us, it got a failed repsonse when checking the chainId, or that the chainId did not match.
can you look at this
Error HH101: Hardhat was set to use chain id 1, but connected to a chain with id 9998.
HardhatError: HH101: Hardhat was set to use chain id 1, but connected to a chain with id 9998.
at ChainIdValidatorProvider.request (/Users/a/Downloads/hardhat/node_modules/hardhat/src/internal/core/providers/chainId.ts:57:15)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async /Users/a/Downloads/hardhat/node_modules/@nomicfoundation/hardhat-viem/src/internal/chains.ts:71:10
at async getChain (/Users/a/Downloads/hardhat/node_modules/@nomicfoundation/hardhat-viem/src/internal/chains.ts:15:19)
at async getWalletClients (/Users/a/Downloads/hardhat/node_modules/@nomicfoundation/hardhat-viem/src/internal/clients.ts:69:47)
at async SimpleTaskDefinition.action (/Users/a/Downloads/hardhat/hardhat.config.ts:141:33)
at async Environment._runTaskDefinition (/Users/a/Downloads/hardhat/node_modules/hardhat/src/internal/core/runtime-environment.ts:359:14)
at async Environment.run (/Users/a/Downloads/hardhat/node_modules/hardhat/src/internal/core/runtime-environment.ts:192:14)
at async main (/Users/a/Downloads/hardhat/node_modules/hardhat/src/internal/cli/cli.ts:323:7)
Error in plugin @nomicfoundation/hardhat-viem: No network with chain id 9998 found. You can override the chain by passing it as a parameter to the client getter:
import { someChain } from "viem/chains";
const client = await hre.viem.getPublicClient({
chain: someChain,
...
});
You can find a list of supported networks here: https://github.com/wevm/viem/blob/main/src/chains/index.ts
For more info run Hardhat with --show-stack-traces
It still says that it is not supported, how to solve it?
Hi @phpmac , this looks like an issue with zitcoin rather than Hardhat. Could you try to write a node script without hardhat and connect with just raw Viem? If you're able to do that, then probably there is an error on the Hardhat side and we'll take a look. If your script with Viem works, please also share it here. Thanks
Closing because no answer was provided in the last 3 weeks
hardhat/hardhat.config.ts
import { vars, type HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox-viem";
const config: HardhatUserConfig = {
// solidity: "0.8.24",
solidity: {
compilers: [
{
version: "0.8.24",
settings: {
optimizer: {
enabled: true,
// ! 设置压缩率为500防止栈溢出
runs: 200,
},
},
},
// 0.5.16
{
version: "0.5.16",
settings: {
optimizer: {
enabled: true,
// ! 设置压缩率为500防止栈溢出
runs: 200,
},
},
},
// 0.6.6
{
version: "0.6.6",
settings: {
optimizer: {
enabled: true,
// ! 设置压缩率为500防止栈溢出
runs: 200,
},
},
},
// 0.4.18
{
version: "0.4.18",
settings: {
optimizer: {
enabled: true,
// ! 设置压缩率为500防止栈溢出
runs: 200,
},
},
},
],
},
networks: {
eth: {
url: "https://rpc.ankr.com/eth",
accounts: [vars.get("PRIVATE_KEY")],
},
ztc: {
url: "https://zitcoin.us/",
accounts: [vars.get("PRIVATE_KEY")],
},
},
};
export default config;
hardhat/scripts/swap.ts
const { core } = await hre.ignition.deploy(CoreModule, {
parameters: {
// 传入指定合约的参数
CoreModule: { feeToSetter },
},
});
Warning:
hardhat:core:config Loading Hardhat config from /Users/a/Downloads/v2/hardhat/hardhat.config.ts +0ms
hardhat:core:hre Creating HardhatRuntimeEnvironment +0ms
hardhat:core:hre Creating provider for network ztc +53ms
NetworkNotFoundError: No network with chain id 9998 found. You can override the chain by passing it as a parameter to the client getter:
import { someChain } from "viem/chains";
const client = await hre.viem.getPublicClient({
chain: someChain,
...
});
You can find a list of supported networks here: https://github.com/wevm/viem/blob/main/src/chains/index.ts
at getChain (/Users/a/Downloads/v2/hardhat/node_modules/@nomicfoundation/hardhat-viem/src/internal/chains.ts:43:13)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async getPublicClient (/Users/a/Downloads/v2/hardhat/node_modules/@nomicfoundation/hardhat-viem/src/internal/clients.ts:29:47)
at async Promise.all (index 0)
at async getContractAt (/Users/a/Downloads/v2/hardhat/node_modules/@nomicfoundation/hardhat-viem/src/internal/contracts.ts:216:58)
at async /Users/a/Downloads/v2/hardhat/node_modules/@nomicfoundation/hardhat-ignition-viem/src/viem-ignition-helper.ts:179:13
at async Promise.all (index 0)
at async Function._toViemContracts (/Users/a/Downloads/v2/hardhat/node_modules/@nomicfoundation/hardhat-ignition-viem/src/viem-ignition-helper.ts:175:7)
at async main (/Users/a/Downloads/v2/hardhat/scripts/swap.ts:18:20)
hardhat:core:scripts-runner Script scripts/swap.ts exited with status code 1 +4s
hardhat:core:cli Killing Hardhat after successfully running task run +0ms
Can you test this? As long as the chainid is not supported by viem it gives this error, don't know about deploying with hre.ignition.deploy+chainid, never solved this problem!