-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove getProvider(chainId) and replace it with a simpler getProvider…
…() which only looks for JSON_RPC_URL in the env vars - this makes the library more flexible when working with new / other chains
- Loading branch information
1 parent
3b44a3b
commit cc94ac3
Showing
6 changed files
with
38 additions
and
38 deletions.
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,9 +1 @@ | ||
export MAINNET_RPC_URL='' | ||
export OPTIMISM_MAINNET_RPC_URL='' | ||
export BASE_MAINNET_RPC_URL='' | ||
export ARBITRUM_MAINNET_RPC_URL='' | ||
|
||
export SEPOLIA_RPC_URL='' | ||
export OPTIMISM_SEPOLIA_RPC_URL='' | ||
export BASE_SEPOLIA_RPC_URL='' | ||
export ARBITRUM_SEPOLIA_RPC_URL='' | ||
export JSON_RPC_URL='' |
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
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,28 +1,11 @@ | ||
import { JsonRpcProvider } from "@ethersproject/providers"; | ||
|
||
type Providers = { [k: string]: JsonRpcProvider }; | ||
|
||
// eg. | ||
// https://mainnet.infura.io/v3/<YOUR-API-KEY> | ||
const providers: Providers = { | ||
// mainnets | ||
1: new JsonRpcProvider(process.env.ETHEREUM_MAINNET_RPC_URL), | ||
10: new JsonRpcProvider(process.env.OPTIMISM_MAINNET_RPC_URL), | ||
8453: new JsonRpcProvider(process.env.BASE_MAINNET_RPC_URL), | ||
42161: new JsonRpcProvider(process.env.ARBITRUM_MAINNET_RPC_URL), | ||
// testnets | ||
84532: new JsonRpcProvider(process.env.BASE_SEPOLIA_RPC_URL), | ||
421614: new JsonRpcProvider(process.env.ARBITRUM_SEPOLIA_RPC_URL), | ||
11155111: new JsonRpcProvider(process.env.SEPOLIA_RPC_URL), | ||
11155420: new JsonRpcProvider(process.env.OPTIMISM_SEPOLIA_RPC_URL), | ||
}; | ||
|
||
export const getProvider = (chainId: string): JsonRpcProvider => { | ||
const provider = providers[chainId]; | ||
|
||
if (!provider) { | ||
throw new Error(`No provider for chainId ${chainId}`); | ||
export const getProvider = (): JsonRpcProvider => { | ||
if (!process.env.JSON_RPC_URL) { | ||
throw new Error( | ||
`No provider available - likely missing 'process.env.JSON_RPC_URL', see README about proper installation` | ||
); | ||
} | ||
|
||
return provider; | ||
return new JsonRpcProvider(process.env.JSON_RPC_URL); | ||
}; |