<- Articles
Using thirdweb with viem

The thirdweb SDK v5 comes with a set of prebuilt adapters, allowing you to use it alongside popular web3 SDKs such as viem, ethers v5 and ethers v6. With the viemAdapter, you can easily switch between the following primitives:

- Smart contract instances
- Client (thirdweb Client ↔ viem Public client)
- Wallet client

Below are some examples:

Converting a thirdweb contract instance to viem
import { getContract } from "thirdweb"; import { viemAdapter } from "thirdweb/adapters/viem"; const thirdwebContract = getContract({ address: "0x...", chain: yourChain, client: yourThirdwebClient, }); // Convert to viem contract const viemContract = await viemAdapter.contract.toViem({ thirdwebContract });
Converting a viem contract to thirdweb
import { viemAdapter } from "thirdweb/adapters/viem"; const contract = viemAdapter.contract.fromViem({ viemContract: viemContract, chain: yourChain, client: yourThirdwebClient, });
Converting a thirdweb Client to viem public client
import { createThirdwebClient } from "thirdweb"; import { viemAdapter } from "thirdweb/adapters/viem"; const thirdwebClient = createThirdwebClient({ clientId: "" }); const viemPublicClient = viemAdapter.publicClient.toViem({ client: thirdwebClient, chain: yourChain, });
Converting thirdweb’s wallet client to viem
import { viemAdapter } from "thirdweb/adapters/viem"; const walletClient = viemAdapter.walletClient.toViem({ account: wallet, // see: https://portal.thirdweb.com/typescript/v5/wallets client: thirdwebClient, chain: yourChain, });
Converting viem’s wallet client to thirdweb
import { viemAdapter } from "thirdweb/adapters/viem"; // To learn more about Account // see: https://portal.thirdweb.com/typescript/v5/wallets const account = viemAdapter.walletClient.fromViem({ walletClient, });