-
Notifications
You must be signed in to change notification settings - Fork 86
[Feature] Overwrite RPC URL #883
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
[Feature] Overwrite RPC URL #883
Conversation
…wraps every chain API. It now builds an overridden networkConfig with the resolved RPC URL and a cloned chainConfig whose rpcUrls.default.http and rpcUrls['public'].http use the override. All downstream consumers (state manager, chain APIs, contracts) automatically use the overridden RPC via the standard construction path. No per-method wrapping needed.
const importName = importNameMap[network]; | ||
const baseModule: any = (networks as any)[importName]; | ||
|
||
// apply override |
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.
looks confusing but purely for observability / checking the logs to see if they are correctly applied.
const networks = await import('@lit-protocol/networks'); | ||
|
||
// choose module by NETWORK env (same way init.ts does) | ||
const network = process.env.NETWORK || 'naga-dev'; |
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.
There are several places that do this, we will optimise in a follow up PR.
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.
makes sense to me, looks good
WHAT
Previously, we added support for specifying a private RPC URL in the artillery test, which was great as it resolved the artillery issue. However, the SDK itself should also allow overwriting the RPC URL. This is important for servers running our SDK long term, as they will eventually hit the RPC URL rate limit.
I was thinking we could do something like this initially:
but this is not a good solution, because the
nagaDev
module is a singleton that has already captured the hardcoded RPC when it was instantiated. Overwriting methods on the sharednetworkModule
insidecreateLitClient
is risky because it might have global side effects.Solution
Add a
.withOverrides
method on the network module. It’s safer, more testable, and lets you spin up multiple clients with different RPCs without stepping on each other.eg.
TEST
Docs Update
https://github.com/LIT-Protocol/docs-v2/pull/1/files