Read below to learn how to best integrate Privy alongside these libraries.
Viem
Viem represents connected wallets as either an account object, which can sign with the wallet, or a wallet client object, which can also send transactions from the wallet.Getting an account
To get an account for a user’s connected wallet, import thetoViemAccount
method and the useWallets
hook from the React SDK.ConnectedWallet
object for your user’s wallet to the method, which will return a LocalAccount
instance.account
to sign messages, typed data payloads, and transactions.Getting a wallet client
To get a viem wallet client for a user’s connected wallet, first import your desired network from theviem/chains
package and import the createWalletClient
method and custom
transport from viem
:wallets
array and switch its network to the chain you imported, using the wallet’s switchChain
method:getEthereumProvider
method and pass it to viem’s createWalletClient
method like so:Wagmi
Privy is fully compatible withwagmi
. Please see our wagmi guide for setting up the integration.Ethers
Ethers v5
Ethers v6
Web3.js
Web3.js represents connected wallets as a Web3 object, which you can use to get information about the current wallet or the request signatures and transactions.To get a Web3js provider for a user’s connected wallet, first find your desired wallet from thewallets
array and switch it to your desired network, using the wallet’s switchChain
method:getEthereumProvider
method and pass it to Web3js’s Web3
constructor like so: