Viem
Learn how to integrate Capsule with Viem for both v1 and v2
Viem is a TypeScript interface for Ethereum, providing low-level primitives for interacting with Ethereum. This guide will show you how to integrate Capsule’s wallet and signing capabilities with both Viem v2 (recommended) and v1.
Prerequisites
Before integrating Capsule with Viem, ensure you have:
- Set up authentication with Capsule. See our Getting Started guides for details.
- Configured the Capsule client in your application
If you haven’t set up Capsule authentication yet, complete one of our authentication tutorials first and return to this guide when you’re ready to implement Viem integration.
Viem v2
Installation
Choose your preferred package manager to install the required dependencies:
Usage
First, set up the Capsule account and Viem client:
Example of signing a transaction:
Viem v1 (Legacy)
Installation
Install the v1-specific integration package:
Usage
The setup process for v1 is similar to v2:
Example transaction signing with v1:
Server-Side Usage
While Viem can be used in both client and server environments, some considerations apply when using it server-side with Capsule. For server-side signing operations, please refer to our Server-Side Signing Guide for specific instructions.
When using Viem server-side, ensure you’re following proper security practices and handling authentication appropriately.