Alchemy AccountKit
Learn how to integrate Alchemy AccountKit with a Capsule Signer for smart account creation and UserOp management in your application.
Introduction
Account Kit enables smart account creation and management for every user in your application. Using Account Kit with Capsule, you can:
- Create and manage smart accounts directly in your app
- Submit gasless transactions using Alchemy’s Gas Manager
- Execute batch transactions via UserOperations
- Handle transactions without requiring users to leave your application
Prerequisites
Before you begin, ensure you have:
- A Capsule API key from the Capsule Developer Portal
- An Alchemy API key from the Alchemy Dashboard
- Optional: An Alchemy Gas Policy ID for gasless transactions
- Already set up authentication with Capsule. See our Getting Started guides for details.
For gasless transactions, you’ll need to set up a Gas Manager Policy in your Alchemy Dashboard. This allows you to sponsor gas fees for your users’ transactions.
Installation
Setup
1. Create Capsule Viem Client
First, create a Viem client configured with your Capsule account:
2. Implement Custom Sign Message
Due to MPC requirements, implement a custom sign message function to handle the signature’s v value:
3. Configure Viem Client with Custom Sign Message
Override the default signMessage method:
4. Initialize Alchemy Client
Create the Alchemy client with your configuration:
Usage
Creating UserOperations
UserOperations represent transaction intentions that will be executed by your smart account. Here’s an example of creating and executing a batch of UserOperations:
UserOperations are bundled together and executed in a single transaction, making them more gas-efficient than executing multiple separate transactions.
Handling Gas Management
When using Alchemy’s Gas Manager, transactions can be executed without requiring users to have ETH in their account:
Error Handling
When working with UserOperations, handle potential errors appropriately:
If you need access to Capsule or help getting set up, please refer to our quick start guide: