Skip to main content

Ethers v5 Adapter

The Ethers v5 Adapter provides integration with ethers.js v5, enabling you to use all CoW Protocol SDK packages with ethers providers and signers.

Installation

Constructor

Parameters

Provider | string
required
An ethers v5 Provider instance or an RPC URL string. If a string is provided, a JsonRpcProvider will be created automatically.
Signer | string
An ethers v5 Signer instance (e.g., Wallet) or a private key string.

Properties

signer

Returns the EthersV5SignerAdapter instance. Throws an error if no signer was provided.

utils

Utility methods for working with ethers v5 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). Useful for compatibility with older protocols.

IntChainIdTypedDataV4Signer

Signer class for EIP-712 typed data version 4 with integer chain ID handling to fix MetaMask compatibility issues.

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>

getTransactionReceipt

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

getStorageAt

Returns the value from a storage position at a given address.
  • address (string) - Contract address
  • slot (string) - Storage slot
Returns: Promise<BytesLike>

call

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

readContract

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

getBlock

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

getContract

Creates a contract instance.
  • address (string) - Contract address
  • abi (ContractInterface) - Contract ABI
Returns: GenericContract

setSigner

Sets or updates the signer for the adapter.
  • signer (Signer | string) - New signer or private key

setProvider

Sets or updates the provider for the adapter.
  • provider (Provider | string) - New provider or RPC URL

signerOrNull

Returns the signer adapter or null if not set.
Returns: EthersV5SignerAdapter | null

createSigner

Creates a new signer adapter from a Signer instance or private key.
  • signerOrPrivateKey (Signer | string) - Signer or private key
Returns: EthersV5SignerAdapter

Usage Examples

With Provider and Wallet

With RPC URL String

With CoW SDK

Using Individual SDK Packages

Using TypedDataV3Signer

See Also

Last modified on March 11, 2026