@nomiclabs/buidler
Version:
Buidler is an extensible developer tool that helps smart contract developers increase productivity by reliably bringing together the tools they want.
27 lines (21 loc) • 794 B
text/typescript
import { IEthereumProvider } from "../../../types";
import { BuidlerError } from "../errors";
import { ERRORS } from "../errors-list";
import { createChainIdGetter, rpcQuantityToNumber } from "./provider-utils";
import { wrapSend } from "./wrapper";
export function createChainIdValidationProvider(
provider: IEthereumProvider,
chainId?: number
) {
const getChainId = createChainIdGetter(provider);
return wrapSend(provider, async (method: string, params: any[]) => {
const realChainId = await getChainId();
if (chainId !== undefined && realChainId !== chainId) {
throw new BuidlerError(ERRORS.NETWORK.INVALID_GLOBAL_CHAIN_ID, {
configChainId: chainId,
connectionChainId: realChainId,
});
}
return provider.send(method, params);
});
}