Skip to main content

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 instance
Account | `0x${string}`
A viem account from privateKeyToAccount or similar
WalletClient
A viem WalletClient, useful with wagmi’s useWalletClient hook

Properties

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.
Returns: Promise<number>

getCode

Returns the bytecode at a given address.
  • address (string) - Contract address
Returns: Promise<string | undefined>

getTransactionReceipt

Returns the transaction receipt for a given transaction hash.
  • hash (string) - Transaction hash
Returns: Promise<TransactionReceipt | null>

getStorageAt

Returns the value from a storage position at a given address.
  • address (string) - Contract address
  • slot (`0x${string}`) - Storage slot
Returns: Promise<`0x${string}`>

call

Executes a read-only call to a contract.
  • txParams (CallParameters) - Transaction parameters
  • provider (PublicClient) - Optional provider override
Returns: Promise<string>

readContract

Reads from a contract function.
  • address (string) - Contract address
  • abi (Abi) - Contract ABI
  • functionName (string) - Function to call
  • args (unknown[]) - Function arguments
  • provider (PublicClient) - Optional provider override
Returns: Promise<unknown>

getBlock

Returns block information for a given block tag.
  • blockTag (BlockTag) - Block identifier
  • provider (PublicClient) - Optional provider override
Returns: Promise<Block>

getContract

Creates a contract instance with a compatible interface.
  • address (string) - Contract address
  • abi (Abi) - Contract ABI
Returns: 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.
Returns: ViemSignerAdapter | null

createSigner

Creates a new signer adapter from an account or private key.
  • signer (Account | PrivateKey | WalletClient) - Signer source
Returns: ViemSignerAdapter

Usage Examples

With Wagmi

With Private Key

With CoW SDK

See Also

Last modified on March 11, 2026