Get client by provider instead of importing the correct chain #361
-
Dealing with a website that uses a LOT of chains. Kind of a nuisance to create a wallet client for each chain. Would be nice to somehow be able to derive what chain you need for your client based on the provider. Any ideas? Doing the following but it's a pain to get the typescript right.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
If you don't care about bundle size and tree-shaking (which you generally should), then you can certainly do this. However, I'd not use a wildcard import for that but instead set up a strict const mapping of |
Beta Was this translation helpful? Give feedback.
If you don't care about bundle size and tree-shaking (which you generally should), then you can certainly do this. However, I'd not use a wildcard import for that but instead set up a strict const mapping of
[chain id] => [chain]
for the chains you plan to support. Otherwise, you are including literally every single chain in your final app bundle (throwing tree shaking out the window essentially). Another benefit is that, through the strict const mapping of chain ids & chains, you'd be able to infer the resulting type with a type guard more easily.