Using viem with server wallets
viem
is a popular TypeScript library on EVM for executing onchain actions with wallets. Privy’s server wallets on EVM natively integrate with viem
, allowing you to use the library’s interfaces for signing messages, signing typed data, sending transactions, and more.
To integrate with viem
, first install version 2^
of the library as a peer dependency:
Then, use Privy’s createViemAccount
method to initialize an instance of a viem Account
for an EVM server wallet. As a parameter to this method, pass an object with the following:
Field | Type | Description |
---|---|---|
walletId | string | ID of the wallet. |
address | 0x${string} | Ethereum address of the wallet. |
privy | PrivyClient | Instance of the Privy client for your app. |
As an example, you can initialize an Account
like so:
From the returned Account
, you can then initialize a viem WalletClient
to sign messages and execute transactions with the wallet like so:
Was this page helpful?