-
Notifications
You must be signed in to change notification settings - Fork 277
Description
Describe the improvement you're thinking about
Currently, the SemaphoreViem
class always creates its own PublicClient instance internally. In many modern dapp architectures (such as those using wagmi or viem context), the application already manages a PublicClient at a higher level.
It would be a significant improvement to allow users to pass an existing PublicClient via the options object.
If provided, the class should use this client instead of creating a new one. This would prevent duplicate network connections, ensure consistent configuration, and improve integration with React/wagmi-based apps.
Describe alternatives you've considered
Continuing to require the class to always create its own client.
Downside: This leads to inefficiency, possible inconsistent state, and makes integration with frameworks like wagmi more difficult.
Using a global singleton or context to "auto-detect" a client.
Additional context
Many dapp frameworks (wagmi, RainbowKit, etc.) encourage a single, shared PublicClient for all blockchain reads. Supporting injection will make SemaphoreViem`` much more composable and easier to use in these environments. This change would be backwards compatible: if no
publicClient` is provided, the class would still create its own as before.