Viem Adapter
The Viem Adapter provides integration with the viem library, enabling you to use all CoW Protocol SDK packages with viem clients and accounts.Installation
Constructor
Parameters
PublicClient
required
A viem
createPublicClient instanceAccount | `0x${string}`
A viem account from
privateKeyToAccount or similarWalletClient
A viem WalletClient, useful with wagmi’s
useWalletClient hookProperties
signer
Returns the ViemSignerAdapter instance. Throws an error if no signer was provided.utils
Utility methods for working with viem types and contracts.TypedDataVersionedSigner
Signer class for EIP-712 typed data with version support.TypedDataV3Signer
Signer class for EIP-712 typed data version 3 (legacy).IntChainIdTypedDataV4Signer
Signer class for EIP-712 typed data version 4 with integer chain ID handling.Methods
getChainId
Returns the chain ID from the connected provider.Promise<number>
getCode
Returns the bytecode at a given address.address(string) - Contract address
Promise<string | undefined>
getTransactionReceipt
Returns the transaction receipt for a given transaction hash.hash(string) - Transaction hash
Promise<TransactionReceipt | null>
getStorageAt
Returns the value from a storage position at a given address.address(string) - Contract addressslot(`0x${string}`) - Storage slot
Promise<`0x${string}`>
call
Executes a read-only call to a contract.txParams(CallParameters) - Transaction parametersprovider(PublicClient) - Optional provider override
Promise<string>
readContract
Reads from a contract function.address(string) - Contract addressabi(Abi) - Contract ABIfunctionName(string) - Function to callargs(unknown[]) - Function argumentsprovider(PublicClient) - Optional provider override
Promise<unknown>
getBlock
Returns block information for a given block tag.blockTag(BlockTag) - Block identifierprovider(PublicClient) - Optional provider override
Promise<Block>
getContract
Creates a contract instance with a compatible interface.address(string) - Contract addressabi(Abi) - Contract ABI
GenericContract
setSigner
Sets or updates the signer for the adapter.signer(Account | PrivateKey | WalletClient) - New signer
setProvider
Sets or updates the provider for the adapter.provider(PublicClient) - New provider
signerOrNull
Returns the signer adapter or null if not set.ViemSignerAdapter | null
createSigner
Creates a new signer adapter from an account or private key.signer(Account | PrivateKey | WalletClient) - Signer source
ViemSignerAdapter