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:
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 });
import { viemAdapter } from "thirdweb/adapters/viem"; const contract = viemAdapter.contract.fromViem({ viemContract: viemContract, chain: yourChain, client: yourThirdwebClient, });
import { createThirdwebClient } from "thirdweb"; import { viemAdapter } from "thirdweb/adapters/viem"; const thirdwebClient = createThirdwebClient({ clientId: "" }); const viemPublicClient = viemAdapter.publicClient.toViem({ client: thirdwebClient, chain: yourChain, });
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, });
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, });