Interfacing with common libraries
Read below to learn how to best integrate Privy alongside these libraries.
Viem
Viem represents connected wallets as a wallet client object, which you can use to get information about the current wallet or the request signatures and transactions.
To get a viem wallet client for a user’s connected wallet, first import your desired network from the viem/chains
package and import the createWalletClient
method and custom
transport from viem
:
Then, find your desired wallet from the wallets
array and switch its network to the chain you imported, using the wallet’s switchChain
method:
Lastly, get the wallet’s EIP1193 provider using the wallet’s getEthereumProvider
method and pass it to viem’s createWalletClient
method like so:
You can then use the wallet client to get information about the wallet or request signatures and transactions.
Wagmi
Privy is fully compatible with wagmi
. 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 the wallets
array and switch it to your desired network, using the wallet’s switchChain
method:
Then, get the wallet’s EIP1193 provider using the wallet’s getEthereumProvider
method and pass it to Web3js’s Web3
constructor like so:
You can then use the Web3 provider to get information about the wallet or request signatures and transactions.
Read below to learn how to best integrate Privy alongside these libraries.
Viem
Viem represents connected wallets as a wallet client object, which you can use to get information about the current wallet or the request signatures and transactions.
To get a viem wallet client for a user’s connected wallet, first import your desired network from the viem/chains
package and import the createWalletClient
method and custom
transport from viem
:
Then, find your desired wallet from the wallets
array and switch its network to the chain you imported, using the wallet’s switchChain
method:
Lastly, get the wallet’s EIP1193 provider using the wallet’s getEthereumProvider
method and pass it to viem’s createWalletClient
method like so:
You can then use the wallet client to get information about the wallet or request signatures and transactions.
Wagmi
Privy is fully compatible with wagmi
. 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 the wallets
array and switch it to your desired network, using the wallet’s switchChain
method:
Then, get the wallet’s EIP1193 provider using the wallet’s getEthereumProvider
method and pass it to Web3js’s Web3
constructor like so:
You can then use the Web3 provider to get information about the wallet or request signatures and transactions.
Third-party libraries may require additional shims to be used in a React Native environment.
Integrating with viem
First, import the necessary methods, objects, and networks from viem
:
Next, get an EIP-1193 provider for the user’s embedded wallet, and switch its network to your desired network:
Lastly, initialize a viem Wallet Client from the EIP-1193 provider:
You can now use methods implemented by viem’s Wallet Client, including signMessage
, signTypedData
, and sendTransaction
!
Integrating with ethers
First, import ethers
:
Next, get an EIP-1193 provider for the user’s embedded wallet, and switch its network to your desired network:
Lastly, initialize an ethers provider and signer from this EIP-1193 provider:
You can then use methods implemented by ethers’ providers and signers, including signMessage
and sendTransaction
.
Integrating with web3.js
First, import web3
:
Next, get an EIP-1193 provider for the user’s embedded wallet, and switch its network to your desired network:
Lastly, initialize an ethers provider and signer from this EIP-1193 provider:
You can then use interfaces by web3.js for signing messages, sending transactions, and more.