ethers5Adapter
The ethers5 adapter provides a way to convert between Thirdweb contracts, accounts, and providers.
let ethers5Adapter: { contract: { fromEthers: ( options: FromEthersContractOptions, toEthers: (options: { }) => Promise<Contract>; }; provider: { toEthers: (options: { }) => Provider; }; signer: { toEthers: (options: { }) => Promise<ThirdwebAdapterSigner>; };};
Converts a ThirdwebContract to an ethers.js Contract or the other way around.
type contract = { fromEthers: ( options: FromEthersContractOptions, toEthers: (options: { }) => Promise<Contract>;};
toEthers
import { ethers5Adapter } from "thirdweb/adapters/ethers5";const ethersContract = await ethers5Adapter.contract.toEthers({ thirdwebContract,});
fromEthers
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.
type provider = { toEthers: (options: { }) => 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: { }) => Promise<ThirdwebAdapterSigner>;};
fromEthers
import { ethers5Adapter } from "thirdweb/adapters/ethers5";const wallet = await ethers5Adapter.signer.fromEthers({ signer });
toEthers
import { ethers5Adapter } from "thirdweb/adapters/ethers5";const signer = await ethers5Adapter.signer.toEthers({ client, chain, account,});