-
Notifications
You must be signed in to change notification settings - Fork 34
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
Potential Fallback Provider (Solves #22) #39
Conversation
Tagging #22 to add this to the issue history... didn't realize that adding it to the title wouldn't reference it |
@@ -189,6 +189,15 @@ const essentialEth = new JsonRpcProvider( | |||
const essentialEth = new JsonRpcProvider(); | |||
``` | |||
|
|||
If you want to use a fallback provider in case your main provider fails: |
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.
👌 Awesome documentation!
@@ -19,6 +20,7 @@ export { | |||
isAddress, | |||
jsonRpcProvider, | |||
JsonRpcProvider, | |||
FallbackProvider, |
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.
Perfect exporting ✅
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.
Great first work!
/** | ||
* Helper function to avoid "new" | ||
*/ | ||
export function jsonRpcProvider(rpcUrl?: string) { |
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.
This export seems to be left-over from copying this file in. We won't need this here, let's just export one class
returnTransactionObjects = false, | ||
): Promise<Block> { | ||
const firstCall = new JsonRpcProvider(this._rpcUrls[0]); | ||
return firstCall.getBlock('latest').catch((e) => { |
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.
This is a good first-solution, let's make this dynamic for any quantity of RPC url's before merging
_rpcUrls: Array<string>; | ||
constructor(rpcUrls?: Array<string>) { | ||
this._rpcUrls = rpcUrls || [ | ||
'https://free-eth-junk.com/api/eth', |
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.
I recall we did this for initial testing, but I think before going live with this we'll probably want this to be just the one valid RPC endpoint
import { Network } from '../types/Network.types'; | ||
import { JsonRpcProvider } from './JsonRpcProvider'; | ||
import chainsInfo from './utils/chains-info'; | ||
export class FallbackProvider { |
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.
Let's extend from a shared class here before merging this.
Here's an example of how Ethers.js does this: https://github.com/ethers-io/ethers.js/blob/73a46efea32c3f9a4833ed77896a216e3d3752a0/packages/providers/src.ts/fallback-provider.ts#L403
And they extend this BaseProvider
/** | ||
* The URL to your Eth node. Consider POKT or Infura | ||
*/ | ||
_rpcUrls: Array<string>; |
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.
Let's make sure this is private
and readonly
which we'll do soon to the JsonRpcProvider
here: #42
Closing this PR in favor of #44 actually, sorry for not getting to your comments! |
Inelegant but functional way to add a fallback provider in case the first JSONRpc fails. Currently only supports one other RPC, i.e. one preferred RPC and one fallback.
Not ready to be merged into main but can be forked and used in situations where this functionality is crucial.