-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add RPC provider: Infura #7286
Open
avkos
wants to merge
10
commits into
4.x
Choose a base branch
from
ok/6975-Add-RPC-provider-Infura
base: 4.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+202
−53
Open
Add RPC provider: Infura #7286
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4ba5fee
Add infura provider
avkos 2cc6f2e
fix infura provider
avkos cda00cc
fix infura test and skip it
avkos 16576db
refactor
avkos 6a2238d
Merge branch '4.x' into ok/6975-Add-RPC-provider-Infura
avkos 92bd039
remove unnecessary test
avkos 0e0d70d
add changelog
avkos 6117711
Merge branch '4.x' into ok/6975-Add-RPC-provider-Infura
avkos 7cfb629
Merge branch '4.x' into ok/6975-Add-RPC-provider-Infura
avkos 8f44a50
Update web3_provider_infura.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 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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"drips": { | ||
"ethereum": { | ||
"ownedBy": "0x04E504Acb5f6A9CB387fa37ec5Fc457A9D36D371" | ||
} | ||
} | ||
"drips": { | ||
"ethereum": { | ||
"ownedBy": "0x04E504Acb5f6A9CB387fa37ec5Fc457A9D36D371" | ||
} | ||
} | ||
} |
This file contains 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 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 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 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,83 @@ | ||
/* | ||
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; | ||
|
||
export class InfuraProvider< | ||
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, | ||
token = '', | ||
host = '', | ||
providerConfigOptions?: HttpProviderOptions | SocketOptions, | ||
) { | ||
super(network, transport, token, host, providerConfigOptions); | ||
} | ||
public static readonly networkHostMap: { [key: string]: string } = { | ||
[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) { | ||
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}/${ | ||
transport === Transport.WebSocket ? 'ws/' : '' | ||
}v3/${token}`; | ||
} | ||
} |
This file contains 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 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
41 changes: 0 additions & 41 deletions
41
packages/web3/test/integration/external-providers/infura-rpc.test.ts
This file was deleted.
Oops, something went wrong.
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.