Skip to content

Support for Lightweight Alternative (Viem) in place of Ethers #5

@comarquet

Description

@comarquet

Feature Request:

I would like to request a new feature to extend the capabilities of this package by adding an option to use the Viem library instead of ethers for a more lightweight implementation.

Background

Currently, the chainView function heavily relies on ethers, particularly ContractFactory, JsonRpcProvider, and Interface. While ethers is powerful, it is also a relatively heavy library. In certain applications, especially those focused on reducing bundle size or optimizing performance, a lighter-weight library like Viem would be preferable.

Why Viem?

Viem is a minimalistic, faster alternative to ethers with a smaller footprint. It is well-suited for developers who need a simpler solution and care about minimizing code size.

Requested Implementation

Provide an alternative chainView function or a variant that utilizes the Viem library to perform the same core actions:

  1. Interacting with a JSON-RPC provider for deploying and simulating smart contracts.
  2. Parsing ABI and error information to provide detailed feedback.
  3. Constructing contract transactions and decoding the responses.

Below are some considerations:

  • Provider: Replace JsonRpcProvider with a corresponding Viem RPC client.
  • Interface: Adapt ABI parsing using Viem's simplified interface functions.
  • Contract Interaction: Replace ContractFactory with Viem methods to construct and simulate contracts.
  • Error Handling: Viem may provide different utilities for handling errors. We would need to ensure error parsing is consistent to maintain a smooth user experience.

Benefits

  • Performance: Viem's lower weight means less overhead, making the solution better optimized for environments like serverless functions or dApps with strict bundle size requirements.
  • Usability: Developers who already prefer Viem for its speed and simplicity will find the proposed implementation more consistent with their existing tooling.

Backward Compatibility

To ensure that this change does not break existing applications, I propose that either:

  • The package supports an option to choose between ethers and viem, providing backward compatibility for ethers users while adding an option for Viem users.
  • Or create a separate method (e.g., chainViewViem) that uses Viem as a dependency.

Conclusion

This feature will allow developers to benefit from a more streamlined and efficient way of interacting with the blockchain, thus expanding the usability of the package while maintaining flexibility. I am happy to contribute if needed or help test the Viem implementation.

Thanks for considering this enhancement! Looking forward to feedback or any suggestions on how we can proceed with this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions