Skip to main content

Ethers v6 Adapter

Overview

The Ethers v6 Adapter integrates the CoW Protocol SDK with ethers.js v6, enabling usage of all SDK packages with ethers v6 providers and signers.

Installation

Initialization

Create an adapter instance by providing a provider and optional signer:
Constructor Parameters:
  • provider: An ethers v6 Provider instance or RPC URL string (automatically creates JsonRpcProvider)
  • signer: Optional ethers v6 Signer instance or private key string

Core Properties

  • signer: Returns the EthersV6SignerAdapter instance; throws error if unavailable
  • utils: Utility methods for working with ethers v6 types and contracts
  • TypedDataVersionedSigner: EIP-712 signer with version support
  • TypedDataV3Signer: EIP-712 version 3 legacy signer
  • IntChainIdTypedDataV4Signer: EIP-712 version 4 signer with MetaMask compatibility fixes

Available Methods

Chain & State Methods

  • getChainId(): Returns promise resolving to chain ID number
  • getCode(address): Retrieves bytecode at specified address
  • getTransactionReceipt(hash): Fetches transaction receipt or null
  • getStorageAt(address, slot): Returns storage value at position
  • getBlock(blockTag, provider?): Retrieves block information

Contract Interaction

  • call(txParams, provider?): Executes read-only contract call
  • readContract({address, abi, functionName, args, provider?}): Reads contract function
  • getContract(address, abi): Creates compatible contract instance

Signer & Provider Management

  • setSigner(signer): Updates the signer
  • setProvider(provider): Updates the provider
  • signerOrNull(): Returns signer adapter or null
  • createSigner(signerOrPrivateKey): Creates new signer adapter

Implementation Examples

Basic Setup with RPC String

Integration with CoW SDK

MetaMask Browser Integration

Last modified on March 4, 2026