Overview
The CDP SDK is compatible withviem
in a couple ways:
- viem Local Accounts can be set as the owner of a CDP Smart Account. See the Signer Example below.
- CDP accounts can be wrapped into viem Custom Accounts using the
toAccount
function. See the Wallet Client Example below.
Signer Example
You can create a viem Local Account and set it as the owner of a CDP Smart Account.main.ts
Wallet Client Example
You can pass a CDP account to thetoAccount
function and get back a viem Custom Account, which can be used wherever viem expects an account. For example, you can create a viem Wallet Client from this account and use the Wallet Client to send transactions.
The following code snippet demonstrates how to use a viem Wallet Client to send a transaction.
If you followed the quickstart, you will have a project that you can use to follow along with the example below.
1. Install viem
Installviem
in your project:
2. Create a Wallet Client from a CDP account
Here we usetoAccount
from viem/accounts
to wrap a CDP account in a viem Custom Account, which is immediately passed to the createWalletClient
function to create a viem Wallet Client.
main.ts
- Send a transaction with the Wallet Client
main.ts
- Putting it all together
main.ts
What to read next
- v2 Wallet Accounts: Read more about the types of accounts and networks we support.
- viem: Learn from the official docs on how to get started developing with viem.