Get Provider Chain Data by ChainId (number or hex) Instead of Chain name string #338
Unanswered
Adamj1232
asked this question in
Idea / Feature Request
Replies: 1 comment 6 replies
-
Thanks for creating this discussion! Can you elaborate more on the following. Not sure I fully understand. Code snippets, etc. would be helpful.
|
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Issue: Retrieving chain data when creating a provider with a non-standardized chain name requires mapping the chain ID to the Viem chain name. This introduces additional code complexity and increases the potential for errors.
Solution: Implement a Viem chain object keyed by chain ID, supporting both decimal and hexadecimal formats. It is recommended to primarily use the decimal value since it reflects current industry trends. This approach simplifies the code without adding extra complexity, although it does require developers to update their existing implementations. For backwards compatibility, a similar solution can be provided for currently supported chains and marked as deprecated.
Alternative Solution: Introduce a new Viem method that accepts a chain ID as input (either in hexadecimal or decimal format) and returns the corresponding chain name. This approach maintains backwards compatibility but adds extra weight to the Viem package and increases maintenance requirements when new chains are added.
I would love to open up the conversation more around this topic.
If help is wanted as this conversation evolves I would be happy to create a PR.
Note: I am an engineer at Blocknative and we are currently integrating and loving Viem!
Beta Was this translation helpful? Give feedback.
All reactions