From 4ba5fee593d2698a37b74610f2a83042ae8c2451 Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Wed, 25 Sep 2024 18:55:32 -0400 Subject: [PATCH 1/7] Add infura provider --- packages/web3-rpc-providers/src/index.ts | 1 + packages/web3-rpc-providers/src/types.ts | 7 + .../src/web3_provider_infura.ts | 158 ++++++++++++++++++ .../test/unit/request.test.ts | 43 ++++- .../external-providers/infura-rpc.test.ts | 41 ----- .../test/integration/web3RPCProviders.test.ts | 45 ++++- 6 files changed, 250 insertions(+), 45 deletions(-) create mode 100644 packages/web3-rpc-providers/src/web3_provider_infura.ts delete mode 100644 packages/web3/test/integration/external-providers/infura-rpc.test.ts diff --git a/packages/web3-rpc-providers/src/index.ts b/packages/web3-rpc-providers/src/index.ts index 577d8e6b960..1c28a555c89 100644 --- a/packages/web3-rpc-providers/src/index.ts +++ b/packages/web3-rpc-providers/src/index.ts @@ -19,6 +19,7 @@ import { QuickNodeProvider } from './web3_provider_quicknode.js'; export * from './types.js'; export * from './web3_provider_quicknode.js'; +export * from './web3_provider_infura.js'; export * from './web3_provider.js'; export * from './errors.js'; diff --git a/packages/web3-rpc-providers/src/types.ts b/packages/web3-rpc-providers/src/types.ts index 9fda306ae0d..a12408e892e 100644 --- a/packages/web3-rpc-providers/src/types.ts +++ b/packages/web3-rpc-providers/src/types.ts @@ -35,15 +35,22 @@ export enum Network { ARBITRUM_MAINNET = 'arbitrum_mainnet', ARBITRUM_SEPOLIA = 'arbitrum_sepolia', + ARBITRUM_GOERLI = 'arbitrum_goerli', BASE_MAINNET = 'base_mainnet', BASE_SEPOLIA = 'base_sepolia', + BASE_GOERLI = 'base_foerli', OPTIMISM_MAINNET = 'optimism_mainnet', OPTIMISM_SEPOLIA = 'optimism_sepolia', + OPTIMISM_GOERLI = 'optimism_goerli', BNB_MAINNET = 'bnb_mainnet', BNB_TESTNET = 'bnb_testnet', + + LINEA_MAINNET = 'linea_mainnet', + LINEA_SEPOLIA = 'linea_sepolia', + LINEA_GOERLI = 'linea_goerli', } // Combining the ws types diff --git a/packages/web3-rpc-providers/src/web3_provider_infura.ts b/packages/web3-rpc-providers/src/web3_provider_infura.ts new file mode 100644 index 00000000000..f2117f0048a --- /dev/null +++ b/packages/web3-rpc-providers/src/web3_provider_infura.ts @@ -0,0 +1,158 @@ +/* +This file is part of web3.js. + +web3.js is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +web3.js is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with web3.js. If not, see . +*/ + +import { + EthExecutionAPI, + JsonRpcResponseWithResult, + Web3APIMethod, + Web3APIPayload, + Web3APIReturnType, + Web3APISpec, +} from 'web3-types'; +import { ResponseError } from 'web3-errors'; +import { HttpProviderOptions } from 'web3-providers-http'; +import { Transport, Network, SocketOptions } from './types.js'; +import { Web3ExternalProvider } from './web3_provider.js'; +import { QuickNodeRateLimitError } from './errors.js'; + +const isValid = (str: string) => str !== undefined && str.trim().length > 0; + +export class InfuraProvider< + API extends Web3APISpec = EthExecutionAPI, +> extends Web3ExternalProvider { + // eslint-disable-next-line default-param-last + public constructor( + network: Network = Network.ETH_MAINNET, + transport: Transport = Transport.HTTPS, + token = '', + host = '', + providerConfigOptions?: HttpProviderOptions | SocketOptions, + ) { + super(network, transport, token, host, providerConfigOptions); + } + + public async request< + Method extends Web3APIMethod, + ResultType = Web3APIReturnType, + >( + payload: Web3APIPayload, + requestOptions?: RequestInit, + ): Promise> { + try { + return await super.request(payload, requestOptions); + } catch (error) { + if (error instanceof ResponseError && error.statusCode === 429) { + throw new QuickNodeRateLimitError(error); + } + throw error; + } + } + + // eslint-disable-next-line class-methods-use-this + public getRPCURL(network: Network, transport: Transport, _token: string, _host: string) { + let host = ''; + let token = ''; + + switch (network) { + case Network.ETH_MAINNET: + host = isValid(_host) ? _host : 'mainnet.infura.io'; + token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; + break; + case Network.ETH_GOERLI: + host = isValid(_host) ? _host : 'goerli.infura.io'; + token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; + break; + case Network.ETH_SEPOLIA: + host = isValid(_host) ? _host : 'sepolia.infura.io'; + token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; + break; + + case Network.ARBITRUM_MAINNET: + host = isValid(_host) ? _host : 'arbitrum-mainnet.infura.io'; + token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; + break; + case Network.ARBITRUM_GOERLI: + host = isValid(_host) ? _host : 'arbitrum-goerli.infura.io'; + token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; + break; + case Network.ARBITRUM_SEPOLIA: + host = isValid(_host) ? _host : 'arbitrum-sepolia.infura.io'; + token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; + break; + case Network.BASE_MAINNET: + host = isValid(_host) ? _host : 'base-mainnet.infura.io'; + token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; + break; + case Network.BASE_GOERLI: + host = isValid(_host) ? _host : 'base-goerli.infura.io'; + token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; + break; + case Network.BASE_SEPOLIA: + host = isValid(_host) ? _host : 'base-sepolia.infura.io'; + token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; + break; + case Network.BNB_MAINNET: + host = isValid(_host) ? _host : 'bnbsmartchain-mainnet.infura.io'; + token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; + break; + case Network.BNB_TESTNET: + host = isValid(_host) ? _host : 'bnbsmartchain-testnet.infura.io'; + token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; + break; + case Network.LINEA_MAINNET: + host = isValid(_host) ? _host : 'linea-mainnet.infura.io'; + token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; + break; + case Network.LINEA_GOERLI: + host = isValid(_host) ? _host : 'linea-goerli.infura.io'; + token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; + break; + case Network.LINEA_SEPOLIA: + host = isValid(_host) ? _host : 'linea-sepolia.infura.io'; + token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; + break; + case Network.POLYGON_MAINNET: + host = isValid(_host) ? _host : 'polygon-mainnet.infura.io'; + token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; + break; + case Network.POLYGON_AMONY: + host = isValid(_host) ? _host : 'polygon-amoy.infura.io'; + token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; + break; + case Network.POLYGON_MUMBAI: + host = isValid(_host) ? _host : 'polygon-mumbai.infura.io'; + token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; + break; + case Network.OPTIMISM_MAINNET: + host = isValid(_host) ? _host : 'optimism-mainnet.infura.io'; + token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; + break; + case Network.OPTIMISM_GOERLI: + host = isValid(_host) ? _host : 'optimism-goerli.infura.io'; + token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; + break; + case Network.OPTIMISM_SEPOLIA: + host = isValid(_host) ? _host : 'optimism-sepolia.infura.io'; + token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; + break; + default: + throw new Error('Network info not avalible.'); + } + + return `${transport}://${host}/${token}`; + } +} diff --git a/packages/web3-rpc-providers/test/unit/request.test.ts b/packages/web3-rpc-providers/test/unit/request.test.ts index 3de14fc0513..bf59a5ff93b 100644 --- a/packages/web3-rpc-providers/test/unit/request.test.ts +++ b/packages/web3-rpc-providers/test/unit/request.test.ts @@ -20,6 +20,7 @@ import { Network, Transport } from '../../src/types'; import { Web3ExternalProvider } from '../../src/web3_provider'; import { QuickNodeRateLimitError } from '../../src/errors'; import { QuickNodeProvider } from '../../src/web3_provider_quicknode'; +import { InfuraProvider } from '../../src/web3_provider_infura'; jest.mock('web3-providers-ws', () => { return { @@ -82,7 +83,7 @@ describe('Web3ExternalProvider', () => { expect(result).toEqual({ result: 'mock-result' }); }); - it('should throw a rate limiting error when status code is 429', async () => { + it('QuickNodeProvider: should throw a rate limiting error when status code is 429', async () => { const network: Network = Network.ETH_MAINNET; const transport: Transport = Transport.HTTPS; const token = 'your-token'; @@ -116,6 +117,46 @@ describe('Web3ExternalProvider', () => { const provider = new QuickNodeProvider(network, transport, token); (provider as any).provider = mockHttpProvider; + const payload: Web3APIPayload> = { + method: 'eth_getBalance', + params: ['0x0123456789012345678901234567890123456789', 'latest'], + }; + await expect(provider.request(payload)).rejects.toThrow(QuickNodeRateLimitError); + }); + it('InfuraProvider: should throw a rate limiting error when status code is 429', async () => { + const network: Network = Network.ETH_MAINNET; + const transport: Transport = Transport.HTTPS; + const token = 'your-token'; + + const mockHttpProvider = { + request: jest.fn(), + }; + + // Create a mock ResponseError with status code 429 + // Create a mock JsonRpcResponse to pass to ResponseError + const mockJsonRpcResponse: JsonRpcResponse = { + jsonrpc: '2.0', + id: '458408f4-7e2c-43f1-b61d-1fe09a9ee25a', + error: { + code: 429, + message: 'Rate limit exceeded', + }, + }; + + // Create a mock ResponseError with status code 429 + const mockError = new ResponseError( + mockJsonRpcResponse, + undefined, + undefined, // request can be undefined + 429, // statusCode + ); + + // Mock the request method to throw the ResponseError + mockHttpProvider.request.mockRejectedValue(mockError); + + const provider = new InfuraProvider(network, transport, token); + (provider as any).provider = mockHttpProvider; + const payload: Web3APIPayload> = { method: 'eth_getBalance', params: ['0x0123456789012345678901234567890123456789', 'latest'], diff --git a/packages/web3/test/integration/external-providers/infura-rpc.test.ts b/packages/web3/test/integration/external-providers/infura-rpc.test.ts deleted file mode 100644 index 479949c06f8..00000000000 --- a/packages/web3/test/integration/external-providers/infura-rpc.test.ts +++ /dev/null @@ -1,41 +0,0 @@ -/* -This file is part of web3.js. - -web3.js is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -web3.js is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with web3.js. If not, see . -*/ - -import Web3 from '../../../src/index'; -import { describeIf, isIpc, itIf } from '../../shared_fixtures/system_tests_utils'; - -describeIf(!isIpc)('compatibility with `infura` remote rpc providers', () => { - itIf( - process.env.INFURA_GOERLI_WS - ? process.env.INFURA_GOERLI_WS.toString().includes('ws') - : false, - )('should create Web3 class instance with `ws` string connection', () => { - const web3 = new Web3(process.env.INFURA_GOERLI_WS); - // eslint-disable-next-line jest/no-standalone-expect - expect(web3).toBeInstanceOf(Web3); - }); - - itIf( - process.env.INFURA_GOERLI_HTTP - ? process.env.INFURA_GOERLI_HTTP.toString().includes('http') - : false, - )('should create Web3 class instance with `http` string connection', () => { - const web3 = new Web3(process.env.INFURA_GOERLI_HTTP); - // eslint-disable-next-line jest/no-standalone-expect - expect(web3).toBeInstanceOf(Web3); - }); -}); diff --git a/packages/web3/test/integration/web3RPCProviders.test.ts b/packages/web3/test/integration/web3RPCProviders.test.ts index 1faeffad452..f2dc5db7ad2 100644 --- a/packages/web3/test/integration/web3RPCProviders.test.ts +++ b/packages/web3/test/integration/web3RPCProviders.test.ts @@ -15,12 +15,12 @@ You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ -import { mainnet, Network, QuickNodeProvider, Transport } from 'web3-rpc-providers'; +import { mainnet, Network, QuickNodeProvider, InfuraProvider, Transport } from 'web3-rpc-providers'; import { Web3 } from '../../src/index'; describe('Web3 RPC Provider Integration tests', () => { const transports = Object.values(Transport); - const networks = [ + const quickNodeNetworks = [ Network.ETH_MAINNET, Network.ETH_HOLESKY, Network.ETH_SEPOLIA, @@ -33,7 +33,7 @@ describe('Web3 RPC Provider Integration tests', () => { ]; transports.forEach(transport => { - networks.forEach(network => { + quickNodeNetworks.forEach(network => { it(`QuickNodeProvider should work with ${transport} transport and ${network} network`, async () => { const provider = new QuickNodeProvider(network, transport); const web3 = new Web3(provider); @@ -48,6 +48,45 @@ describe('Web3 RPC Provider Integration tests', () => { }); }); }); + + const infuraNetworks = [ + Network.ETH_MAINNET, + Network.ETH_GOERLI, + Network.ETH_SEPOLIA, + Network.ARBITRUM_MAINNET, + Network.ARBITRUM_GOERLI, + Network.ARBITRUM_SEPOLIA, + Network.BASE_MAINNET, + Network.BASE_GOERLI, + Network.BASE_SEPOLIA, + Network.BNB_MAINNET, + Network.BNB_TESTNET, + Network.LINEA_MAINNET, + Network.LINEA_GOERLI, + Network.LINEA_SEPOLIA, + Network.POLYGON_MAINNET, + Network.POLYGON_AMONY, + Network.POLYGON_MUMBAI, + Network.OPTIMISM_MAINNET, + Network.OPTIMISM_GOERLI, + Network.OPTIMISM_SEPOLIA, + ]; + transports.forEach(transport => { + infuraNetworks.forEach(network => { + it(`InfuraProvider should work with ${transport} transport and ${network} network`, async () => { + const provider = new InfuraProvider(network, transport); + const web3 = new Web3(provider); + const result = await web3.eth.getBlockNumber(); + + expect(typeof result).toBe('bigint'); + expect(result > 0).toBe(true); + + if (transport === Transport.WebSocket) { + web3.provider?.disconnect(); + } + }); + }); + }); it(`should work with mainnet provider`, async () => { const web3 = new Web3(mainnet); const result = await web3.eth.getBlockNumber(); From 2cc6f2e754297af9030bec3fdb5ba5cd576b5101 Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Wed, 25 Sep 2024 19:27:39 -0400 Subject: [PATCH 2/7] fix infura provider --- packages/web3-rpc-providers/src/types.ts | 26 ++++- .../src/web3_provider_infura.ts | 97 +++++++++++-------- .../test/integration/web3RPCProviders.test.ts | 29 ++++-- 3 files changed, 101 insertions(+), 51 deletions(-) diff --git a/packages/web3-rpc-providers/src/types.ts b/packages/web3-rpc-providers/src/types.ts index a12408e892e..364ec3c60c8 100644 --- a/packages/web3-rpc-providers/src/types.ts +++ b/packages/web3-rpc-providers/src/types.ts @@ -25,10 +25,28 @@ export enum Transport { export enum Network { ETH_MAINNET = 'eth_mainnet', - ETH_GOERLI = 'eth_goerli', ETH_SEPOLIA = 'eth_sepolia', + ETH_GOERLI = 'eth_goerli', ETH_HOLESKY = 'eth_holesky', + PALM_MAINNET = 'palm_mainnet', + PALM_TESTNET = 'palm_testnet', + + BLAST_MAINNET = 'blast_mainnet', + BLAST_SEPOLIA = 'blast_sepolia', + + STARKNET_MAINNET = 'starknet_mainnet', + STARKNET_SEPOLIA = 'starknet_sepolia', + + ZKSYNC_MAINNET = 'zksync_mainnet', + ZKSYNC_SEPOLIA = 'zksync_sepolia', + + CELO_MAINNET = 'celo_mainnet', + CELO_ALFAJORES = 'celo_alfajores', + + AVALANCHE_MAINNET = 'avalanche_mainnet', + AVALANCHE_FUJI = 'avalanche_fuji', + POLYGON_MAINNET = 'polygon_mainnet', POLYGON_MUMBAI = 'polygon_mumbai', POLYGON_AMONY = 'polygon_amony', @@ -48,6 +66,12 @@ export enum Network { BNB_MAINNET = 'bnb_mainnet', BNB_TESTNET = 'bnb_testnet', + BSC_MAINNET = 'bsc_mainnet', + BSC_TESTNET = 'bsc_testnet', + + MANTLE_MAINNET = 'mantle_mainnet', + MANTLE_SEPOLIA = 'mantle_sepolia', + LINEA_MAINNET = 'linea_mainnet', LINEA_SEPOLIA = 'linea_sepolia', LINEA_GOERLI = 'linea_goerli', diff --git a/packages/web3-rpc-providers/src/web3_provider_infura.ts b/packages/web3-rpc-providers/src/web3_provider_infura.ts index f2117f0048a..6d0b70ced2d 100644 --- a/packages/web3-rpc-providers/src/web3_provider_infura.ts +++ b/packages/web3-rpc-providers/src/web3_provider_infura.ts @@ -63,96 +63,107 @@ export class InfuraProvider< } // eslint-disable-next-line class-methods-use-this - public getRPCURL(network: Network, transport: Transport, _token: string, _host: string) { + public getRPCURL(network: Network, transport: Transport, token: string, _host: string) { let host = ''; - let token = ''; switch (network) { + case Network.PALM_MAINNET: + host = isValid(_host) ? _host : 'palm-mainnet.infura.io'; + break; + case Network.PALM_TESTNET: + host = isValid(_host) ? _host : 'palm-testnet.infura.io'; + break; + case Network.BLAST_MAINNET: + host = isValid(_host) ? _host : 'blast-mainnet.infura.io'; + break; + case Network.BLAST_SEPOLIA: + host = isValid(_host) ? _host : 'blast-sepolia.infura.io'; + break; + case Network.AVALANCHE_MAINNET: + host = isValid(_host) ? _host : 'avalanche-mainnet.infura.io'; + break; + case Network.AVALANCHE_FUJI: + host = isValid(_host) ? _host : 'avalanche-fuji.infura.io'; + break; + case Network.STARKNET_MAINNET: + host = isValid(_host) ? _host : 'starknet-mainnet.infura.io'; + break; + case Network.STARKNET_SEPOLIA: + host = isValid(_host) ? _host : 'starknet-sepolia.infura.io'; + break; + case Network.ZKSYNC_MAINNET: + host = isValid(_host) ? _host : 'zksync-mainnet.infura.io'; + break; + case Network.ZKSYNC_SEPOLIA: + host = isValid(_host) ? _host : 'zksync-sepolia.infura.io'; + break; + case Network.CELO_MAINNET: + host = isValid(_host) ? _host : 'celo-mainnet.infura.io'; + break; + case Network.CELO_ALFAJORES: + host = isValid(_host) ? _host : 'celo-alfajores.infura.io'; + break; + case Network.BSC_MAINNET: + host = isValid(_host) ? _host : 'bsc-mainnet.infura.io'; + break; + case Network.BSC_TESTNET: + host = isValid(_host) ? _host : 'bsc-testnet.infura.io'; + break; + case Network.MANTLE_MAINNET: + host = isValid(_host) ? _host : 'mantle-mainnet.infura.io'; + break; + case Network.MANTLE_SEPOLIA: + host = isValid(_host) ? _host : 'mantle-sepolia.infura.io'; + break; case Network.ETH_MAINNET: host = isValid(_host) ? _host : 'mainnet.infura.io'; - token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; break; - case Network.ETH_GOERLI: - host = isValid(_host) ? _host : 'goerli.infura.io'; - token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; + case Network.ETH_HOLESKY: + host = isValid(_host) ? _host : 'holesky.infura.io'; break; case Network.ETH_SEPOLIA: host = isValid(_host) ? _host : 'sepolia.infura.io'; - token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; break; - case Network.ARBITRUM_MAINNET: host = isValid(_host) ? _host : 'arbitrum-mainnet.infura.io'; - token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; - break; - case Network.ARBITRUM_GOERLI: - host = isValid(_host) ? _host : 'arbitrum-goerli.infura.io'; - token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; break; case Network.ARBITRUM_SEPOLIA: host = isValid(_host) ? _host : 'arbitrum-sepolia.infura.io'; - token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; break; case Network.BASE_MAINNET: host = isValid(_host) ? _host : 'base-mainnet.infura.io'; - token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; - break; - case Network.BASE_GOERLI: - host = isValid(_host) ? _host : 'base-goerli.infura.io'; - token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; break; case Network.BASE_SEPOLIA: host = isValid(_host) ? _host : 'base-sepolia.infura.io'; - token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; break; case Network.BNB_MAINNET: - host = isValid(_host) ? _host : 'bnbsmartchain-mainnet.infura.io'; - token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; + host = isValid(_host) ? _host : 'opbnb-mainnet.infura.io'; break; case Network.BNB_TESTNET: - host = isValid(_host) ? _host : 'bnbsmartchain-testnet.infura.io'; - token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; + host = isValid(_host) ? _host : 'opbnb-testnet.infura.io'; break; case Network.LINEA_MAINNET: host = isValid(_host) ? _host : 'linea-mainnet.infura.io'; - token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; - break; - case Network.LINEA_GOERLI: - host = isValid(_host) ? _host : 'linea-goerli.infura.io'; - token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; break; case Network.LINEA_SEPOLIA: host = isValid(_host) ? _host : 'linea-sepolia.infura.io'; - token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; break; case Network.POLYGON_MAINNET: host = isValid(_host) ? _host : 'polygon-mainnet.infura.io'; - token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; break; case Network.POLYGON_AMONY: host = isValid(_host) ? _host : 'polygon-amoy.infura.io'; - token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; - break; - case Network.POLYGON_MUMBAI: - host = isValid(_host) ? _host : 'polygon-mumbai.infura.io'; - token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; break; case Network.OPTIMISM_MAINNET: host = isValid(_host) ? _host : 'optimism-mainnet.infura.io'; - token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; - break; - case Network.OPTIMISM_GOERLI: - host = isValid(_host) ? _host : 'optimism-goerli.infura.io'; - token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; break; case Network.OPTIMISM_SEPOLIA: host = isValid(_host) ? _host : 'optimism-sepolia.infura.io'; - token = isValid(_token) ? _token : '3240624a343867035925ff7561eb60dfdba2a668'; break; default: throw new Error('Network info not avalible.'); } - return `${transport}://${host}/${token}`; + return `${transport}://${host}/v3/${token}`; } } diff --git a/packages/web3/test/integration/web3RPCProviders.test.ts b/packages/web3/test/integration/web3RPCProviders.test.ts index f2dc5db7ad2..2d06b2a1e0a 100644 --- a/packages/web3/test/integration/web3RPCProviders.test.ts +++ b/packages/web3/test/integration/web3RPCProviders.test.ts @@ -50,31 +50,46 @@ describe('Web3 RPC Provider Integration tests', () => { }); const infuraNetworks = [ + Network.PALM_MAINNET, + Network.PALM_TESTNET, + Network.BLAST_MAINNET, + Network.BLAST_SEPOLIA, + Network.AVALANCHE_MAINNET, + Network.AVALANCHE_FUJI, + Network.STARKNET_MAINNET, + Network.STARKNET_SEPOLIA, + Network.ZKSYNC_MAINNET, + Network.ZKSYNC_SEPOLIA, + Network.CELO_MAINNET, + Network.CELO_ALFAJORES, + Network.BSC_MAINNET, + Network.BSC_TESTNET, + Network.MANTLE_MAINNET, + Network.MANTLE_SEPOLIA, Network.ETH_MAINNET, - Network.ETH_GOERLI, + Network.ETH_HOLESKY, Network.ETH_SEPOLIA, Network.ARBITRUM_MAINNET, - Network.ARBITRUM_GOERLI, Network.ARBITRUM_SEPOLIA, Network.BASE_MAINNET, - Network.BASE_GOERLI, Network.BASE_SEPOLIA, Network.BNB_MAINNET, Network.BNB_TESTNET, Network.LINEA_MAINNET, - Network.LINEA_GOERLI, Network.LINEA_SEPOLIA, Network.POLYGON_MAINNET, Network.POLYGON_AMONY, - Network.POLYGON_MUMBAI, Network.OPTIMISM_MAINNET, - Network.OPTIMISM_GOERLI, Network.OPTIMISM_SEPOLIA, ]; transports.forEach(transport => { infuraNetworks.forEach(network => { it(`InfuraProvider should work with ${transport} transport and ${network} network`, async () => { - const provider = new InfuraProvider(network, transport); + const provider = new InfuraProvider( + network, + transport, + process.env.INFURA_PROVIDER_KEY, + ); const web3 = new Web3(provider); const result = await web3.eth.getBlockNumber(); From cda00cc05fe4780dcf8914516fe614581e6c0f53 Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Thu, 26 Sep 2024 12:21:11 -0400 Subject: [PATCH 3/7] fix infura test and skip it --- .../src/web3_provider_infura.ts | 7 ++- .../test/integration/web3RPCProviders.test.ts | 55 ++++++++++++++----- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/packages/web3-rpc-providers/src/web3_provider_infura.ts b/packages/web3-rpc-providers/src/web3_provider_infura.ts index 6d0b70ced2d..fb2cbcd6cc9 100644 --- a/packages/web3-rpc-providers/src/web3_provider_infura.ts +++ b/packages/web3-rpc-providers/src/web3_provider_infura.ts @@ -25,7 +25,7 @@ import { } from 'web3-types'; import { ResponseError } from 'web3-errors'; import { HttpProviderOptions } from 'web3-providers-http'; -import { Transport, Network, SocketOptions } from './types.js'; +import { Network, SocketOptions, Transport } from './types.js'; import { Web3ExternalProvider } from './web3_provider.js'; import { QuickNodeRateLimitError } from './errors.js'; @@ -163,7 +163,8 @@ export class InfuraProvider< default: throw new Error('Network info not avalible.'); } - - return `${transport}://${host}/v3/${token}`; + return `${transport}://${host}/${ + transport === Transport.WebSocket ? 'ws/' : '' + }v3/${token}`; } } diff --git a/packages/web3/test/integration/web3RPCProviders.test.ts b/packages/web3/test/integration/web3RPCProviders.test.ts index 2d06b2a1e0a..ef1ac5e25d6 100644 --- a/packages/web3/test/integration/web3RPCProviders.test.ts +++ b/packages/web3/test/integration/web3RPCProviders.test.ts @@ -18,6 +18,7 @@ along with web3.js. If not, see . import { mainnet, Network, QuickNodeProvider, InfuraProvider, Transport } from 'web3-rpc-providers'; import { Web3 } from '../../src/index'; +jest.setTimeout(10000); describe('Web3 RPC Provider Integration tests', () => { const transports = Object.values(Transport); const quickNodeNetworks = [ @@ -84,22 +85,48 @@ describe('Web3 RPC Provider Integration tests', () => { ]; transports.forEach(transport => { infuraNetworks.forEach(network => { - it(`InfuraProvider should work with ${transport} transport and ${network} network`, async () => { - const provider = new InfuraProvider( - network, - transport, - process.env.INFURA_PROVIDER_KEY, - ); - const web3 = new Web3(provider); - const result = await web3.eth.getBlockNumber(); + // skip not exists endpoints + if ( + !( + [ + Network.PALM_MAINNET, + Network.PALM_TESTNET, + Network.BLAST_SEPOLIA, + Network.STARKNET_MAINNET, + Network.STARKNET_SEPOLIA, + Network.ZKSYNC_SEPOLIA, + Network.BSC_TESTNET, + Network.MANTLE_SEPOLIA, + Network.BNB_TESTNET, + ].includes(network) && transport === Transport.WebSocket + ) + ) { + it.skip(`InfuraProvider should work with ${transport} transport and ${network} network`, async () => { + const provider = new InfuraProvider( + network, + transport, + process.env.INFURA_PROVIDER_KEY, + ); - expect(typeof result).toBe('bigint'); - expect(result > 0).toBe(true); + const web3 = new Web3(provider); + const result = + network === Network.STARKNET_MAINNET || network === Network.STARKNET_SEPOLIA + ? BigInt( + await web3.requestManager.send({ + method: 'starknet_blockNumber', + params: [], + }), + ) + : await web3.eth.getBlockNumber(); - if (transport === Transport.WebSocket) { - web3.provider?.disconnect(); - } - }); + expect(typeof result).toBe('bigint'); + expect(result > 0).toBe(true); + + if (transport === Transport.WebSocket) { + web3.provider?.disconnect(); + } + }); + } }); }); it(`should work with mainnet provider`, async () => { From 16576dbeb813adc5552c6470cb00f34aec6dcd8e Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Thu, 26 Sep 2024 12:33:00 -0400 Subject: [PATCH 4/7] refactor --- .../src/web3_provider_infura.ts | 167 +++++------------- 1 file changed, 40 insertions(+), 127 deletions(-) diff --git a/packages/web3-rpc-providers/src/web3_provider_infura.ts b/packages/web3-rpc-providers/src/web3_provider_infura.ts index fb2cbcd6cc9..eada2b6d0f7 100644 --- a/packages/web3-rpc-providers/src/web3_provider_infura.ts +++ b/packages/web3-rpc-providers/src/web3_provider_infura.ts @@ -15,25 +15,16 @@ You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ -import { - EthExecutionAPI, - JsonRpcResponseWithResult, - Web3APIMethod, - Web3APIPayload, - Web3APIReturnType, - Web3APISpec, -} from 'web3-types'; -import { ResponseError } from 'web3-errors'; +import { EthExecutionAPI, Web3APISpec } from 'web3-types'; import { HttpProviderOptions } from 'web3-providers-http'; import { Network, SocketOptions, Transport } from './types.js'; import { Web3ExternalProvider } from './web3_provider.js'; -import { QuickNodeRateLimitError } from './errors.js'; const isValid = (str: string) => str !== undefined && str.trim().length > 0; export class InfuraProvider< API extends Web3APISpec = EthExecutionAPI, -> extends Web3ExternalProvider { +> extends Web3ExternalProvider { // eslint-disable-next-line default-param-last public constructor( network: Network = Network.ETH_MAINNET, @@ -44,125 +35,47 @@ export class InfuraProvider< ) { super(network, transport, token, host, providerConfigOptions); } - - public async request< - Method extends Web3APIMethod, - ResultType = Web3APIReturnType, - >( - payload: Web3APIPayload, - requestOptions?: RequestInit, - ): Promise> { - try { - return await super.request(payload, requestOptions); - } catch (error) { - if (error instanceof ResponseError && error.statusCode === 429) { - throw new QuickNodeRateLimitError(error); - } - throw error; - } - } - + public static readonly networkHostMap: { [key: string]: string } = { + [Network.PALM_MAINNET]: 'palm-mainnet.infura.io', + [Network.PALM_TESTNET]: 'palm-testnet.infura.io', + [Network.BLAST_MAINNET]: 'blast-mainnet.infura.io', + [Network.BLAST_SEPOLIA]: 'blast-sepolia.infura.io', + [Network.AVALANCHE_MAINNET]: 'avalanche-mainnet.infura.io', + [Network.AVALANCHE_FUJI]: 'avalanche-fuji.infura.io', + [Network.STARKNET_MAINNET]: 'starknet-mainnet.infura.io', + [Network.STARKNET_SEPOLIA]: 'starknet-sepolia.infura.io', + [Network.ZKSYNC_MAINNET]: 'zksync-mainnet.infura.io', + [Network.ZKSYNC_SEPOLIA]: 'zksync-sepolia.infura.io', + [Network.CELO_MAINNET]: 'celo-mainnet.infura.io', + [Network.CELO_ALFAJORES]: 'celo-alfajores.infura.io', + [Network.BSC_MAINNET]: 'bsc-mainnet.infura.io', + [Network.BSC_TESTNET]: 'bsc-testnet.infura.io', + [Network.MANTLE_MAINNET]: 'mantle-mainnet.infura.io', + [Network.MANTLE_SEPOLIA]: 'mantle-sepolia.infura.io', + [Network.ETH_MAINNET]: 'mainnet.infura.io', + [Network.ETH_HOLESKY]: 'holesky.infura.io', + [Network.ETH_SEPOLIA]: 'sepolia.infura.io', + [Network.ARBITRUM_MAINNET]: 'arbitrum-mainnet.infura.io', + [Network.ARBITRUM_SEPOLIA]: 'arbitrum-sepolia.infura.io', + [Network.BASE_MAINNET]: 'base-mainnet.infura.io', + [Network.BASE_SEPOLIA]: 'base-sepolia.infura.io', + [Network.BNB_MAINNET]: 'opbnb-mainnet.infura.io', + [Network.BNB_TESTNET]: 'opbnb-testnet.infura.io', + [Network.LINEA_MAINNET]: 'linea-mainnet.infura.io', + [Network.LINEA_SEPOLIA]: 'linea-sepolia.infura.io', + [Network.POLYGON_MAINNET]: 'polygon-mainnet.infura.io', + [Network.POLYGON_AMONY]: 'polygon-amoy.infura.io', + [Network.OPTIMISM_MAINNET]: 'optimism-mainnet.infura.io', + [Network.OPTIMISM_SEPOLIA]: 'optimism-sepolia.infura.io', + }; // eslint-disable-next-line class-methods-use-this public getRPCURL(network: Network, transport: Transport, token: string, _host: string) { - let host = ''; - - switch (network) { - case Network.PALM_MAINNET: - host = isValid(_host) ? _host : 'palm-mainnet.infura.io'; - break; - case Network.PALM_TESTNET: - host = isValid(_host) ? _host : 'palm-testnet.infura.io'; - break; - case Network.BLAST_MAINNET: - host = isValid(_host) ? _host : 'blast-mainnet.infura.io'; - break; - case Network.BLAST_SEPOLIA: - host = isValid(_host) ? _host : 'blast-sepolia.infura.io'; - break; - case Network.AVALANCHE_MAINNET: - host = isValid(_host) ? _host : 'avalanche-mainnet.infura.io'; - break; - case Network.AVALANCHE_FUJI: - host = isValid(_host) ? _host : 'avalanche-fuji.infura.io'; - break; - case Network.STARKNET_MAINNET: - host = isValid(_host) ? _host : 'starknet-mainnet.infura.io'; - break; - case Network.STARKNET_SEPOLIA: - host = isValid(_host) ? _host : 'starknet-sepolia.infura.io'; - break; - case Network.ZKSYNC_MAINNET: - host = isValid(_host) ? _host : 'zksync-mainnet.infura.io'; - break; - case Network.ZKSYNC_SEPOLIA: - host = isValid(_host) ? _host : 'zksync-sepolia.infura.io'; - break; - case Network.CELO_MAINNET: - host = isValid(_host) ? _host : 'celo-mainnet.infura.io'; - break; - case Network.CELO_ALFAJORES: - host = isValid(_host) ? _host : 'celo-alfajores.infura.io'; - break; - case Network.BSC_MAINNET: - host = isValid(_host) ? _host : 'bsc-mainnet.infura.io'; - break; - case Network.BSC_TESTNET: - host = isValid(_host) ? _host : 'bsc-testnet.infura.io'; - break; - case Network.MANTLE_MAINNET: - host = isValid(_host) ? _host : 'mantle-mainnet.infura.io'; - break; - case Network.MANTLE_SEPOLIA: - host = isValid(_host) ? _host : 'mantle-sepolia.infura.io'; - break; - case Network.ETH_MAINNET: - host = isValid(_host) ? _host : 'mainnet.infura.io'; - break; - case Network.ETH_HOLESKY: - host = isValid(_host) ? _host : 'holesky.infura.io'; - break; - case Network.ETH_SEPOLIA: - host = isValid(_host) ? _host : 'sepolia.infura.io'; - break; - case Network.ARBITRUM_MAINNET: - host = isValid(_host) ? _host : 'arbitrum-mainnet.infura.io'; - break; - case Network.ARBITRUM_SEPOLIA: - host = isValid(_host) ? _host : 'arbitrum-sepolia.infura.io'; - break; - case Network.BASE_MAINNET: - host = isValid(_host) ? _host : 'base-mainnet.infura.io'; - break; - case Network.BASE_SEPOLIA: - host = isValid(_host) ? _host : 'base-sepolia.infura.io'; - break; - case Network.BNB_MAINNET: - host = isValid(_host) ? _host : 'opbnb-mainnet.infura.io'; - break; - case Network.BNB_TESTNET: - host = isValid(_host) ? _host : 'opbnb-testnet.infura.io'; - break; - case Network.LINEA_MAINNET: - host = isValid(_host) ? _host : 'linea-mainnet.infura.io'; - break; - case Network.LINEA_SEPOLIA: - host = isValid(_host) ? _host : 'linea-sepolia.infura.io'; - break; - case Network.POLYGON_MAINNET: - host = isValid(_host) ? _host : 'polygon-mainnet.infura.io'; - break; - case Network.POLYGON_AMONY: - host = isValid(_host) ? _host : 'polygon-amoy.infura.io'; - break; - case Network.OPTIMISM_MAINNET: - host = isValid(_host) ? _host : 'optimism-mainnet.infura.io'; - break; - case Network.OPTIMISM_SEPOLIA: - host = isValid(_host) ? _host : 'optimism-sepolia.infura.io'; - break; - default: - throw new Error('Network info not avalible.'); + const defaultHost = InfuraProvider.networkHostMap[network]; + if (!defaultHost) { + throw new Error('Network info not avalible.'); } + const host = isValid(_host) ? _host : defaultHost; + return `${transport}://${host}/${ transport === Transport.WebSocket ? 'ws/' : '' }v3/${token}`; From 92bd0390a2a16adad9a2ee42c8d4cb4237a1ea14 Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Mon, 30 Sep 2024 15:46:16 -0400 Subject: [PATCH 5/7] remove unnecessary test --- .../test/unit/constructor.test.ts | 2 +- .../test/unit/request.test.ts | 41 ------------------- 2 files changed, 1 insertion(+), 42 deletions(-) diff --git a/packages/web3-rpc-providers/test/unit/constructor.test.ts b/packages/web3-rpc-providers/test/unit/constructor.test.ts index cc34cb1fcd3..dfc0e4b25c2 100644 --- a/packages/web3-rpc-providers/test/unit/constructor.test.ts +++ b/packages/web3-rpc-providers/test/unit/constructor.test.ts @@ -23,7 +23,7 @@ import { Web3ExternalProvider } from '../../src/web3_provider'; import { Network, SocketOptions, Transport } from '../../src/types'; import { ProviderConfigOptionsError } from '../../src/errors'; -// Mock implementation so ws doesnt have openhandle after test exits as it attempts to connects at start +// Mock implementation so ws doesnt have openhandle after test exits as it attempts to connect at start jest.mock('isomorphic-ws', () => { return { __esModule: true, diff --git a/packages/web3-rpc-providers/test/unit/request.test.ts b/packages/web3-rpc-providers/test/unit/request.test.ts index bf59a5ff93b..b72a62698ad 100644 --- a/packages/web3-rpc-providers/test/unit/request.test.ts +++ b/packages/web3-rpc-providers/test/unit/request.test.ts @@ -20,7 +20,6 @@ import { Network, Transport } from '../../src/types'; import { Web3ExternalProvider } from '../../src/web3_provider'; import { QuickNodeRateLimitError } from '../../src/errors'; import { QuickNodeProvider } from '../../src/web3_provider_quicknode'; -import { InfuraProvider } from '../../src/web3_provider_infura'; jest.mock('web3-providers-ws', () => { return { @@ -117,46 +116,6 @@ describe('Web3ExternalProvider', () => { const provider = new QuickNodeProvider(network, transport, token); (provider as any).provider = mockHttpProvider; - const payload: Web3APIPayload> = { - method: 'eth_getBalance', - params: ['0x0123456789012345678901234567890123456789', 'latest'], - }; - await expect(provider.request(payload)).rejects.toThrow(QuickNodeRateLimitError); - }); - it('InfuraProvider: should throw a rate limiting error when status code is 429', async () => { - const network: Network = Network.ETH_MAINNET; - const transport: Transport = Transport.HTTPS; - const token = 'your-token'; - - const mockHttpProvider = { - request: jest.fn(), - }; - - // Create a mock ResponseError with status code 429 - // Create a mock JsonRpcResponse to pass to ResponseError - const mockJsonRpcResponse: JsonRpcResponse = { - jsonrpc: '2.0', - id: '458408f4-7e2c-43f1-b61d-1fe09a9ee25a', - error: { - code: 429, - message: 'Rate limit exceeded', - }, - }; - - // Create a mock ResponseError with status code 429 - const mockError = new ResponseError( - mockJsonRpcResponse, - undefined, - undefined, // request can be undefined - 429, // statusCode - ); - - // Mock the request method to throw the ResponseError - mockHttpProvider.request.mockRejectedValue(mockError); - - const provider = new InfuraProvider(network, transport, token); - (provider as any).provider = mockHttpProvider; - const payload: Web3APIPayload> = { method: 'eth_getBalance', params: ['0x0123456789012345678901234567890123456789', 'latest'], From 0e0d70d0886d73da0f32ba366f9feeb79b7468f8 Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Wed, 16 Oct 2024 18:26:58 -0400 Subject: [PATCH 6/7] add changelog --- CHANGELOG.md | 12 ++++++++++++ packages/web3-rpc-providers/CHANGELOG.md | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46c0eefe645..3d6a6041ddb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2734,3 +2734,15 @@ If there are any bugs, improvements, optimizations or any new feature proposal f #### web3-eth - Allow `getEthereumjsTxDataFrom` to return additional fields that may be passed if using a `customTransactionSchema`. + +### Added + +#### web3-rpc-providers + +- InfuraProvider was added (#7286) + +### Fixed + +#### web3-utils + +- fix `padRight` validation failure on large `uint` (#7265) diff --git a/packages/web3-rpc-providers/CHANGELOG.md b/packages/web3-rpc-providers/CHANGELOG.md index a9e2c2a8b79..1c0d8948d7d 100644 --- a/packages/web3-rpc-providers/CHANGELOG.md +++ b/packages/web3-rpc-providers/CHANGELOG.md @@ -59,3 +59,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added optional `HttpProviderOptions | SocketOptions` in `Web3ExternalProvider` and `QuickNodeProvider` for provider configs ## [Unreleased] + +### Added + +- InfuraProvider was added (#7286) From 8f44a50d7a1ebec2c74e026e2498e5e010fed42c Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Mon, 28 Oct 2024 11:51:43 -0400 Subject: [PATCH 7/7] Update web3_provider_infura.ts --- .../src/web3_provider_infura.ts | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/packages/web3-rpc-providers/src/web3_provider_infura.ts b/packages/web3-rpc-providers/src/web3_provider_infura.ts index eada2b6d0f7..04e7fa6d0db 100644 --- a/packages/web3-rpc-providers/src/web3_provider_infura.ts +++ b/packages/web3-rpc-providers/src/web3_provider_infura.ts @@ -36,44 +36,44 @@ export class InfuraProvider< super(network, transport, token, host, providerConfigOptions); } public static readonly networkHostMap: { [key: string]: string } = { - [Network.PALM_MAINNET]: 'palm-mainnet.infura.io', - [Network.PALM_TESTNET]: 'palm-testnet.infura.io', - [Network.BLAST_MAINNET]: 'blast-mainnet.infura.io', - [Network.BLAST_SEPOLIA]: 'blast-sepolia.infura.io', - [Network.AVALANCHE_MAINNET]: 'avalanche-mainnet.infura.io', - [Network.AVALANCHE_FUJI]: 'avalanche-fuji.infura.io', - [Network.STARKNET_MAINNET]: 'starknet-mainnet.infura.io', - [Network.STARKNET_SEPOLIA]: 'starknet-sepolia.infura.io', - [Network.ZKSYNC_MAINNET]: 'zksync-mainnet.infura.io', - [Network.ZKSYNC_SEPOLIA]: 'zksync-sepolia.infura.io', - [Network.CELO_MAINNET]: 'celo-mainnet.infura.io', - [Network.CELO_ALFAJORES]: 'celo-alfajores.infura.io', - [Network.BSC_MAINNET]: 'bsc-mainnet.infura.io', - [Network.BSC_TESTNET]: 'bsc-testnet.infura.io', - [Network.MANTLE_MAINNET]: 'mantle-mainnet.infura.io', - [Network.MANTLE_SEPOLIA]: 'mantle-sepolia.infura.io', - [Network.ETH_MAINNET]: 'mainnet.infura.io', - [Network.ETH_HOLESKY]: 'holesky.infura.io', - [Network.ETH_SEPOLIA]: 'sepolia.infura.io', - [Network.ARBITRUM_MAINNET]: 'arbitrum-mainnet.infura.io', - [Network.ARBITRUM_SEPOLIA]: 'arbitrum-sepolia.infura.io', - [Network.BASE_MAINNET]: 'base-mainnet.infura.io', - [Network.BASE_SEPOLIA]: 'base-sepolia.infura.io', - [Network.BNB_MAINNET]: 'opbnb-mainnet.infura.io', - [Network.BNB_TESTNET]: 'opbnb-testnet.infura.io', - [Network.LINEA_MAINNET]: 'linea-mainnet.infura.io', - [Network.LINEA_SEPOLIA]: 'linea-sepolia.infura.io', - [Network.POLYGON_MAINNET]: 'polygon-mainnet.infura.io', - [Network.POLYGON_AMONY]: 'polygon-amoy.infura.io', - [Network.OPTIMISM_MAINNET]: 'optimism-mainnet.infura.io', - [Network.OPTIMISM_SEPOLIA]: 'optimism-sepolia.infura.io', + [Network.PALM_MAINNET]: 'palm-mainnet', + [Network.PALM_TESTNET]: 'palm-testnet', + [Network.BLAST_MAINNET]: 'blast-mainnet', + [Network.BLAST_SEPOLIA]: 'blast-sepolia', + [Network.AVALANCHE_MAINNET]: 'avalanche-mainnet', + [Network.AVALANCHE_FUJI]: 'avalanche-fuji', + [Network.STARKNET_MAINNET]: 'starknet-mainnet', + [Network.STARKNET_SEPOLIA]: 'starknet-sepolia', + [Network.ZKSYNC_MAINNET]: 'zksync-mainnet', + [Network.ZKSYNC_SEPOLIA]: 'zksync-sepolia', + [Network.CELO_MAINNET]: 'celo-mainnet', + [Network.CELO_ALFAJORES]: 'celo-alfajores', + [Network.BSC_MAINNET]: 'bsc-mainnet', + [Network.BSC_TESTNET]: 'bsc-testnet', + [Network.MANTLE_MAINNET]: 'mantle-mainnet', + [Network.MANTLE_SEPOLIA]: 'mantle-sepolia', + [Network.ETH_MAINNET]: 'mainnet', + [Network.ETH_HOLESKY]: 'holesky', + [Network.ETH_SEPOLIA]: 'sepolia', + [Network.ARBITRUM_MAINNET]: 'arbitrum-mainnet', + [Network.ARBITRUM_SEPOLIA]: 'arbitrum-sepolia', + [Network.BASE_MAINNET]: 'base-mainnet', + [Network.BASE_SEPOLIA]: 'base-sepolia', + [Network.BNB_MAINNET]: 'opbnb-mainnet', + [Network.BNB_TESTNET]: 'opbnb-testnet', + [Network.LINEA_MAINNET]: 'linea-mainnet', + [Network.LINEA_SEPOLIA]: 'linea-sepolia', + [Network.POLYGON_MAINNET]: 'polygon-mainnet', + [Network.POLYGON_AMOY]: 'polygon-amoy', + [Network.OPTIMISM_MAINNET]: 'optimism-mainnet', + [Network.OPTIMISM_SEPOLIA]: 'optimism-sepolia', }; // eslint-disable-next-line class-methods-use-this public getRPCURL(network: Network, transport: Transport, token: string, _host: string) { - const defaultHost = InfuraProvider.networkHostMap[network]; - if (!defaultHost) { + if (!InfuraProvider.networkHostMap[network]) { throw new Error('Network info not avalible.'); } + const defaultHost = `${InfuraProvider.networkHostMap[network]}.infura.io`; const host = isValid(_host) ? _host : defaultHost; return `${transport}://${host}/${