diff --git a/packages/providers/src.ts/alchemy-provider.ts b/packages/providers/src.ts/alchemy-provider.ts index c73645a841..7ba8a28b8a 100644 --- a/packages/providers/src.ts/alchemy-provider.ts +++ b/packages/providers/src.ts/alchemy-provider.ts @@ -20,7 +20,7 @@ const defaultApiKey = "_gg7wSSi0KMBsdKnGVfHDueq6xMB9EkC" export class AlchemyProvider extends UrlJsonRpcProvider { readonly apiKey: string; - static getWebSocketProvider(network: Networkish, apiKey: any): WebSocketProvider { + static getWebSocketProvider(network?: Networkish, apiKey?: any): WebSocketProvider { const provider = new AlchemyProvider(network, apiKey); const url = provider.connection.url.replace(/^http/i, "ws") diff --git a/packages/providers/src.ts/infura-provider.ts b/packages/providers/src.ts/infura-provider.ts index 794d1dd3d8..b7de2fa387 100644 --- a/packages/providers/src.ts/infura-provider.ts +++ b/packages/providers/src.ts/infura-provider.ts @@ -18,7 +18,7 @@ export class InfuraProvider extends UrlJsonRpcProvider { readonly projectId: string; readonly projectSecret: string; - static getWebSocketProvider(network: Networkish, apiKey: any): WebSocketProvider { + static getWebSocketProvider(network?: Networkish, apiKey?: any): WebSocketProvider { const provider = new InfuraProvider(network, apiKey); const connection = provider.connection; if (connection.password) { @@ -44,12 +44,11 @@ export class InfuraProvider extends UrlJsonRpcProvider { apiKeyObj.projectId = apiKey; } else if (apiKey.projectSecret != null) { - if (typeof(apiKey.projectId) !== "string") { - logger.throwArgumentError("projectSecret requires a projectId", "projectId", apiKey.projectId); - } - if (typeof(apiKey.projectSecret) !== "string") { - logger.throwArgumentError("invalid projectSecret", "projectSecret", "[REDACTED]"); - } + logger.assertArgument((typeof(apiKey.projectId) === "string"), + "projectSecret requires a projectId", "projectId", apiKey.projectId); + logger.assertArgument((typeof(apiKey.projectSecret) === "string"), + "invalid projectSecret", "projectSecret", "[REDACTED]"); + apiKeyObj.projectId = apiKey.projectId; apiKeyObj.projectSecret = apiKey.projectSecret; @@ -64,7 +63,7 @@ export class InfuraProvider extends UrlJsonRpcProvider { static getUrl(network: Network, apiKey: any): string | ConnectionInfo { let host: string = null; - switch(network.name) { + switch(network ? network.name: "unknown") { case "homestead": host = "mainnet.infura.io"; break;