Skip to content

Commit

Permalink
feat: jsonrpc and websockets
Browse files Browse the repository at this point in the history
  • Loading branch information
mfw78 committed Apr 2, 2024
1 parent 96acd18 commit 28e5f1c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/services/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class ChainContext {
): Promise<ChainContext> {
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(
Expand Down Expand Up @@ -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));
}

0 comments on commit 28e5f1c

Please sign in to comment.