Have you heard about viem ? 🔥

GabiDev
2 min readJul 25, 2023

--

Viem is a TypeScript Interface for Ethereum that provides low-level stateless primitives for interacting with Ethereum. It was created as an alternative to ethers.js and web3.js with a focus on reliability, efficiency, and excellent developer experience. The creators of Viem, who are also the authors of wagmi, a popular React Hooks library for Ethereum, identified a quadrilemma in the current state of low-level Ethereum interface abstractions: developer experience, stability, bundle size, and performance. They created Viem to address these issues.

Advantages of Viem:
Developer Experience: Viem offers a great developer experience through modular and composable APIs, comprehensive documentation, and automatic type safety and inference. It provides intuitive building blocks for developers to build their Ethereum apps and libraries.

Stability: Viem prioritizes stability. It runs its test suite against a forked Ethereum node, aims for complete test coverage, and tests all potential behavioral cases. It also builds deterministic and pure APIs.

Bundle Size: Viem maintains a low bundle size, which is critical when building web applications. It adopts a minimalist modular architecture to achieve a bundle size of 35kB. Furthermore, Viem is tree-shakable, meaning only the modules you use are included in your final bundle.

Performance: Viem optimizes performance by only executing heavy asynchronous tasks when required and using optimized encoding/parsing algorithms.

Disadvantages of Viem:
The documentation suggests that Viem’s APIs may be more verbose than alternative libraries, which could be seen as a disadvantage for developers who prefer more concise code. However, the creators of Viem believe this verbosity is a worthwhile trade-off for the flexibility it provides.

Comparison with ethers.js:
Ethers.js is another popular library for interacting with Ethereum. While both Viem and ethers.js provide developers with tools to interact with Ethereum, they have different focuses. Ethers.js is known for its simplicity and ease of use, while Viem focuses on providing a robust, efficient, and reliable developer experience.
Viem’s emphasis on a small bundle size and performance optimization may make it a better choice for developers building web applications where load times and efficiency are critical. On the other hand, developers who value simplicity and ease of use may prefer ethers.js.
In terms of stability, both libraries prioritize this aspect, but Viem takes additional steps such as running its test suite against a forked Ethereum node and aiming for complete test coverage.

Example of calling a contract with viem vs ethers v5:

viem

Calling a smart contract with viem library

Ethers

The choice between Viem and ethers.js will depend on the specific needs and preferences of the developer or development team.

--

--