diff --git a/src/services/chain.ts b/src/services/chain.ts index 2784685..9543417 100644 --- a/src/services/chain.ts +++ b/src/services/chain.ts @@ -146,7 +146,7 @@ export class ChainContext { ): Promise { const { rpc, deploymentBlock } = options; - const provider = new providers.WebSocketProvider(rpc); + const provider = getProvider(rpc.toLowerCase()); const chainId = (await provider.getNetwork()).chainId; const registry = await Registry.load( @@ -528,6 +528,16 @@ function _formatResult(result: boolean) { return result ? "✅" : "❌"; } +function getProvider(rpcUrl: string): providers.Provider { + // if the rpcUrl is a websocket url, use the WebSocketProvider + if (rpcUrl.startsWith("ws")) { + return new providers.WebSocketProvider(rpcUrl); + } + + // otherwise, use the JsonRpcProvider + return new providers.JsonRpcProvider(rpcUrl); +} + async function asyncSleep(ms: number) { return new Promise((resolve) => setTimeout(resolve, ms)); }