diff --git a/packages/providers/src.ts/infura-provider.ts b/packages/providers/src.ts/infura-provider.ts index a2d31285c..794d1dd3d 100644 --- a/packages/providers/src.ts/infura-provider.ts +++ b/packages/providers/src.ts/infura-provider.ts @@ -1,8 +1,10 @@ "use strict"; -import { Network } from "@ethersproject/networks"; +import { Network, Networkish } from "@ethersproject/networks"; import { ConnectionInfo } from "@ethersproject/web"; +import { WebSocketProvider } from "./websocket-provider"; + import { Logger } from "@ethersproject/logger"; import { version } from "./_version"; const logger = new Logger(version); @@ -16,6 +18,19 @@ export class InfuraProvider extends UrlJsonRpcProvider { readonly projectId: string; readonly projectSecret: string; + static getWebSocketProvider(network: Networkish, apiKey: any): WebSocketProvider { + const provider = new InfuraProvider(network, apiKey); + const connection = provider.connection; + if (connection.password) { + logger.throwError("INFURA WebSocket project secrets unsupported", Logger.errors.UNSUPPORTED_OPERATION, { + operation: "InfuraProvider.getWebSocketProvider()" + }); + } + + const url = connection.url.replace(/^http/i, "ws").replace("/v3/", "/ws/v3/"); + return new WebSocketProvider(url, network); + } + static getApiKey(apiKey: any): any { const apiKeyObj: { apiKey: string, projectId: string, projectSecret: string } = { apiKey: defaultProjectId,