This repository was archived by the owner on Mar 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Add rpc provider public node #7322
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
77f4237
init
avkos e7c8782
finished
avkos 29e87ee
add unit test
avkos de58ab0
Merge branch '4.x' into ok/6973-Add-RPC-Provider-Public-Node
avkos b7d271c
add changelog
avkos 8ae7eff
Merge branch '4.x' into ok/6973-Add-RPC-Provider-Public-Node
avkos 138a832
Merge branch '4.x' into ok/6973-Add-RPC-Provider-Public-Node
avkos 80e2340
Update CHANGELOG.md
avkos 8a234f0
Update web3_provider_publicnode.ts
avkos 2ea7543
fix
avkos 85a0f06
Update web3_provider_publicnode.ts
avkos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
packages/web3-rpc-providers/src/web3_provider_publicnode.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /* | ||
| 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 <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| 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'; | ||
|
|
||
| const isValid = (str: string) => str !== undefined && str.trim().length > 0; | ||
|
|
||
| const websocketExclusions = [ | ||
| Network.DYMENSION_MAINNET, | ||
| Network.DYMENSION_TESTNET, | ||
| Network.KAVA_MAINNET, | ||
| Network.CRONOS_MAINNET, | ||
| // deprecated | ||
| Network.POLYGON_MAINNET, | ||
| ]; | ||
|
|
||
| export class PublicNodeProvider< | ||
| API extends Web3APISpec = EthExecutionAPI, | ||
| > extends Web3ExternalProvider<API> { | ||
| // eslint-disable-next-line default-param-last | ||
| public constructor( | ||
| network: Network = Network.ETH_MAINNET, | ||
| transport: Transport = Transport.HTTPS, | ||
| host = '', | ||
| providerConfigOptions?: HttpProviderOptions | SocketOptions, | ||
| ) { | ||
| super(network, transport, '', host, providerConfigOptions); | ||
| } | ||
| public static readonly networkHostMap: { [key: string]: string } = { | ||
| [Network.POLYGON_AMOY]: 'polygon-amoy-bor-rpc.publicnode.com', | ||
| [Network.DYMENSION_MAINNET]: 'dymension-evm-rpc.publicnode.com', | ||
| [Network.DYMENSION_TESTNET]: 'dymension-testnet-evm-rpc.publicnode.com', | ||
| [Network.BLAST_MAINNET]: 'blast-rpc.publicnode.com', | ||
| [Network.GNOSIS_MAINNET]: 'gnosis-rpc.publicnode.com', | ||
| [Network.PULSECHAIN_MAINNET]: 'pulsechain-rpc.publicnode.com', | ||
| [Network.PULSECHAIN_TESTNET]: 'pulsechain-testnet-rpc.publicnode.com', | ||
| [Network.KAVA_MAINNET]: 'kava-evm-rpc.publicnode.com', | ||
| [Network.CRONOS_MAINNET]: 'cronos-evm-rpc.publicnode.com', | ||
| [Network.MANTLE_MAINNET]: 'mantle-rpc.publicnode.com', | ||
| [Network.TAIKO_MAINNET]: 'taiko-rpc.publicnode.com', | ||
| [Network.TAIKO_HEKLA]: 'taiko-hekla-rpc.publicnode.com', | ||
| [Network.LINEA_MAINNET]: 'linea-rpc.publicnode.com', | ||
| [Network.LINEA_SEPOLIA]: 'linea-sepolia-rpc.publicnode.com', | ||
| [Network.SCROLL_MAINNET]: 'scroll-rpc.publicnode.com', | ||
| [Network.SCROLL_SEPOLIA]: 'scroll-sepolia-rpc.publicnode.com', | ||
| [Network.SYSCOIN_MAINNET]: 'syscoin-evm-rpc.publicnode.com', | ||
| [Network.SYSCOIN_TANENBAUM]: 'syscoin-tanenbaum-evm-rpc.publicnode.com', | ||
| [Network.HAQQ_MAINNET]: 'haqq-evm-rpc.publicnode.com', | ||
| [Network.EVMOS_MAINNET]: 'evmos-evm-rpc.publicnode.com', | ||
| [Network.EVMOS_TESTNET]: 'evmos-testnet-evm-rpc.publicnode.com', | ||
| [Network.BERACHAIN_TESTNET]: 'berachain-testnet-evm-rpc.publicnode.com', | ||
| [Network.ETH_MAINNET]: 'ethereum-rpc.publicnode.com', | ||
| [Network.ETH_SEPOLIA]: 'ethereum-sepolia-rpc.publicnode.com', | ||
| [Network.ETH_HOLESKY]: 'ethereum-holesky-rpc.publicnode.com', | ||
| [Network.BSC_MAINNET]: 'bsc-rpc.publicnode.com', | ||
| [Network.BSC_TESTNET]: 'bsc-testnet-rpc.publicnode.com', | ||
| [Network.POLYGON_MAINNET]: 'polygon-bor-rpc.publicnode.com', | ||
| [Network.BASE_MAINNET]: 'base-rpc.publicnode.com', | ||
| [Network.BASE_SEPOLIA]: 'base-sepolia-rpc.publicnode.com', | ||
| [Network.ARBITRUM_ONE]: 'arbitrum-one-rpc.publicnode.com', | ||
| [Network.ARBITRUM_NOVA]: 'arbitrum-nova-rpc.publicnode.com', | ||
| [Network.ARBITRUM_SEPOLIA]: 'arbitrum-sepolia-rpc.publicnode.com', | ||
| [Network.AVALANCHE_C_MAINNET]: 'avalanche-c-chain-rpc.publicnode.com', | ||
| [Network.AVALANCHE_P_MAINNET]: 'avalanche-p-chain-rpc.publicnode.com', | ||
| [Network.AVALANCHE_X_MAINNET]: 'avalanche-x-chain-rpc.publicnode.com', | ||
| [Network.AVALANCHE_FUJI_C]: 'avalanche-fuji-c-chain-rpc.publicnode.com', | ||
| [Network.AVALANCHE_FUJI_P]: 'avalanche-fuji-p-chain-rpc.publicnode.com', | ||
| [Network.AVALANCHE_FUJI_X]: 'avalanche-fuji-x-chain-rpc.publicnode.com', | ||
| [Network.OPTIMISM_MAINNET]: 'optimism-rpc.publicnode.com', | ||
| [Network.OPTIMISM_SEPOLIA]: 'optimism-sepolia-rpc.publicnode.com', | ||
| [Network.FANTOM_MAINNET]: 'fantom-rpc.publicnode.com', | ||
| [Network.FANTOM_TESTNET]: 'fantom-testnet-rpc.publicnode.com', | ||
| [Network.OPBNB_MAINNET]: 'opbnb-rpc.publicnode.com', | ||
| [Network.OPBNB_TESTNET]: 'opbnb-testnet-rpc.publicnode.com', | ||
| [Network.GNOSIS_CHIADO]: 'gnosis-chiado-rpc.publicnode.com', | ||
| [Network.CHILIZ_MAINNET]: 'chiliz-rpc.publicnode.com', | ||
| [Network.CHILIZ_SPICY]: 'chiliz-spicy-rpc.publicnode.com', | ||
| [Network.MOONBEAM_MAINNET]: 'moonbeam-rpc.publicnode.com', | ||
| [Network.BAHAMUT_MAINNET]: 'bahamut-rpc.publicnode.com', | ||
| [Network.TRON_MAINNET]: 'tron-evm-rpc.publicnode.com', | ||
| [Network.MOONRIVER_MAINNET]: 'moonriver-rpc.publicnode.com', | ||
| }; | ||
| // eslint-disable-next-line class-methods-use-this | ||
| public getRPCURL(network: Network, transport: Transport, _: string, _host: string) { | ||
| const defaultHost = PublicNodeProvider.networkHostMap[network]; | ||
|
avkos marked this conversation as resolved.
Outdated
|
||
| if (!defaultHost) { | ||
| throw new Error('Network info not avalible.'); | ||
| } | ||
| const host = isValid(_host) ? _host : defaultHost; | ||
| if (websocketExclusions.includes(network) && transport === Transport.WebSocket) { | ||
| return `${transport}://${host}/websocket`; | ||
| } | ||
| return `${transport}://${host}`; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.