@nomicfoundation/hardhat-verify
Version:
Hardhat plugin for verifying contracts
16 lines (11 loc) • 466 B
text/typescript
import type { EthereumProvider } from "hardhat/types/providers";
const chainIdCache = new WeakMap<EthereumProvider, number>();
export async function getChainId(provider: EthereumProvider): Promise<number> {
const cachedChainId = chainIdCache.get(provider);
if (cachedChainId !== undefined) {
return cachedChainId;
}
const chainId = Number(await provider.request({ method: "eth_chainId" }));
chainIdCache.set(provider, chainId);
return chainId;
}