TypeScript SDK
ethers5Adapter
The ethers5 adapter provides a way to convert between Thirdweb contracts, accounts, and providers.
let ethers5Adapter: { contract: { fromEthers: ( options: FromEthersContractOptions, toEthers: (options: { thirdwebContract: Readonly; }) => Promise<Contract>; }; provider: { toEthers: (options: { chain: Readonly; }) => Provider; }; signer: { toEthers: (options: { chain: Readonly; }) => Promise<ThirdwebAdapterSigner>; };};Converts a ThirdwebContract to an ethers.js Contract or the other way around.
type contract = { fromEthers: ( options: FromEthersContractOptions, toEthers: (options: { thirdwebContract: Readonly; }) => Promise<Contract>;};import { ethers5Adapter } from "thirdweb/adapters/ethers5";const ethersContract = await ethers5Adapter.contract.toEthers({ thirdwebContract,});import { ethers5Adapter } from "thirdweb/adapters/ethers5"; const twContract = await ethers5Adapter.contract.fromEthers({ client, ethersContract, chain: defineChain(1), // Replace with your chain});Converts a Thirdweb client and chain ID into an ethers.js provider.
import { ethers5Adapter } from "thirdweb/adapters/ethers5";const provider = ethers5Adapter.provider.toEthers({ client, chainId,});Once you have converted a thirdweb Client to ethers Provider, you can use it like any other ethers provider:
const blockNumber = await provider.getBlockNumber();Converts an ethers5 Signer into a Wallet object or the other way around.
type signer = { toEthers: (options: { chain: Readonly; }) => Promise<ThirdwebAdapterSigner>;};import { ethers5Adapter } from "thirdweb/adapters/ethers5";const wallet = await ethers5Adapter.signer.fromEthers({ signer });import { ethers5Adapter } from "thirdweb/adapters/ethers5";const signer = await ethers5Adapter.signer.toEthers({ client, chain, account,});