viemAdapter
Converts thirdweb accounts and contracts to viem wallet clients and contract objects or the other way around.
let viemAdapter: { contract: { fromViem: (options: FromViemContractOptions<TAbi>) => ThirdwebContract<TAbi>; toViem: { } }; publicClient: { toViem: (options: ToViemPublicClientOptions) => PublicClient }; walletClient: { fromViem: (options: { walletClient: { account: undefined | (Account); addChain: (args: AddChainParameters) => Promise<void>; batch?: { multicall?: boolean | ({ batchSize?: number; wait?: number }) }; cacheTime: number; ccipRead?: false | ({ request?: (parameters: CcipRequestParameters) => Promise<`0x${...}`> }); chain: undefined | (Chain); deployContract: (args: DeployContractParameters<abi, undefined | (Chain), undefined | (Account), chainOverride>) => Promise<`0x${string}`>; extend: (fn: (client: Client<Transport, undefined | (Chain), undefined | (Account), WalletRpcSchema, WalletActions<undefined | (Chain), undefined | (Account)>>) => client) => Client<Transport, undefined | (Chain), undefined | (Account), WalletRpcSchema, ({[K in string | number | symbol] : client[K]}) & (WalletActions<undefined | (Chain), undefined | (Account)>)>; getAddresses: () => Promise<GetAddressesReturnType>; getChainId: () => Promise<number>; getPermissions: () => Promise<GetPermissionsReturnType>; key: string; name: string; pollingInterval: number; prepareTransactionRequest: (args: PrepareTransactionRequestParameters<undefined | (Chain), undefined | (Account), chainOverride, accountOverride, request>) => Promise<{[K in string | number | symbol] : (UnionRequiredBy<..., ...>) & (... extends ... ? ... : ...)[K]}>; request: EIP1193RequestFn<WalletRpcSchema>; requestAddresses: () => Promise<RequestAddressesReturnType>; requestPermissions: (args: { eth_accounts: Record<string, any> }) => Promise<RequestPermissionsReturnType>; sendRawTransaction: (args: SendRawTransactionParameters) => Promise<`0x${string}`>; sendTransaction: (args: SendTransactionParameters<undefined | (Chain), undefined | (Account), chainOverride, request>) => Promise<`0x${string}`>; signMessage: (args: SignMessageParameters<undefined | (Account)>) => Promise<`0x${string}`>; signTransaction: (args: SignTransactionParameters<undefined | (Chain), undefined | (Account), chainOverride, request>) => Promise<TransactionSerialized<GetTransactionType<request, (... extends ... ? ... : ...) | (... extends ... ? ... : ...) | (... extends ... ? ... : ...) | (... extends ... ? ... : ...) | (... extends ... ? ... : ...) | (... extends ... ? ... : ...)>, (GetTransactionType<..., ...> extends "eip1559" ? `0x02${...}` : never) | (GetTransactionType<..., ...> extends "eip2930" ? `0x01${...}` : never) | (GetTransactionType<..., ...> extends "eip4844" ? `0x03${...}` : never) | (GetTransactionType<..., ...> extends "eip7702" ? `0x04${...}` : never) | (GetTransactionType<..., ...> extends "legacy" ? TransactionSerializedLegacy : never)>>; signTypedData: (args: SignTypedDataParameters<typedData, primaryType, undefined | (Account)>) => Promise<`0x${string}`>; switchChain: (args: SwitchChainParameters) => Promise<void>; transport: (TransportConfig<string, EIP1193RequestFn>) & (Record<string, any>); type: string; uid: string; watchAsset: (args: WatchAssetParams) => Promise<boolean>; writeContract: (args: WriteContractParameters<abi, functionName, args, undefined | (Chain), undefined | (Account), chainOverride>) => Promise<`0x${string}`> } }) => Account; toViem: (options: ToViemWalletClientOptions) => WalletClient } }
Creates a ThirdwebContract from a Viem contract or the other way around.
type contract = { fromViem: ( options: FromViemContractOptions<TAbi>, toViem: {};};
fromViem
import { viemAdapter } from "thirdweb/adapters/viem"; const contract = viemAdapter.contract.fromViem({ viemContract: viemContract, chain: ethereum, client,});
toViem
import { viemAdapter } from "thirdweb/adapters";const viemContract = await viemAdapter.contract.toViem({ thirdwebContract,});
Converts a thirdweb account to a Viem Wallet client or the other way around.
type walletClient = { fromViem: (options: { walletClient: { account: undefined | (Account); addChain: (args: AddChainParameters) => Promise<void>; batch?: { multicall?: boolean | ({ batchSize?: number; wait?: number }) }; cacheTime: number; ccipRead?: false | ({ request?: (parameters: CcipRequestParameters) => Promise<`0x${...}`> }); chain: undefined | (Chain); deployContract: (args: DeployContractParameters<abi, undefined | (Chain), undefined | (Account), chainOverride>) => Promise<`0x${string}`>; extend: (fn: (client: Client<Transport, undefined | (Chain), undefined | (Account), WalletRpcSchema, WalletActions<undefined | (Chain), undefined | (Account)>>) => client) => Client<Transport, undefined | (Chain), undefined | (Account), WalletRpcSchema, ({[K in string | number | symbol] : client[K]}) & (WalletActions<undefined | (Chain), undefined | (Account)>)>; getAddresses: () => Promise<GetAddressesReturnType>; getChainId: () => Promise<number>; getPermissions: () => Promise<GetPermissionsReturnType>; key: string; name: string; pollingInterval: number; prepareTransactionRequest: (args: PrepareTransactionRequestParameters<undefined | (Chain), undefined | (Account), chainOverride, accountOverride, request>) => Promise<{[K in string | number | symbol] : (UnionRequiredBy<..., ...>) & (... extends ... ? ... : ...)[K]}>; request: EIP1193RequestFn<WalletRpcSchema>; requestAddresses: () => Promise<RequestAddressesReturnType>; requestPermissions: (args: { eth_accounts: Record<string, any> }) => Promise<RequestPermissionsReturnType>; sendRawTransaction: (args: SendRawTransactionParameters) => Promise<`0x${string}`>; sendTransaction: (args: SendTransactionParameters<undefined | (Chain), undefined | (Account), chainOverride, request>) => Promise<`0x${string}`>; signMessage: (args: SignMessageParameters<undefined | (Account)>) => Promise<`0x${string}`>; signTransaction: (args: SignTransactionParameters<undefined | (Chain), undefined | (Account), chainOverride, request>) => Promise<TransactionSerialized<GetTransactionType<request, (... extends ... ? ... : ...) | (... extends ... ? ... : ...) | (... extends ... ? ... : ...) | (... extends ... ? ... : ...) | (... extends ... ? ... : ...) | (... extends ... ? ... : ...)>, (GetTransactionType<..., ...> extends "eip1559" ? `0x02${...}` : never) | (GetTransactionType<..., ...> extends "eip2930" ? `0x01${...}` : never) | (GetTransactionType<..., ...> extends "eip4844" ? `0x03${...}` : never) | (GetTransactionType<..., ...> extends "eip7702" ? `0x04${...}` : never) | (GetTransactionType<..., ...> extends "legacy" ? TransactionSerializedLegacy : never)>>; signTypedData: (args: SignTypedDataParameters<typedData, primaryType, undefined | (Account)>) => Promise<`0x${string}`>; switchChain: (args: SwitchChainParameters) => Promise<void>; transport: (TransportConfig<string, EIP1193RequestFn>) & (Record<string, any>); type: string; uid: string; watchAsset: (args: WatchAssetParams) => Promise<boolean>; writeContract: (args: WriteContractParameters<abi, functionName, args, undefined | (Chain), undefined | (Account), chainOverride>) => Promise<`0x${string}`> } }) => Account; toViem: (options: ToViemWalletClientOptions) => WalletClient }
toViem
import { viemAdapter } from "thirdweb/adapters/viem"; const walletClient = viemAdapter.walletClient.toViem({ account, client, chain: ethereum,});
fromViem
import { viemAdapter } from "thirdweb/adapters"; const account = viemAdapter.walletClient.fromViem({ walletClient,});