Skip to main content

Overview

The CoW Protocol Python SDK supports multiple blockchain networks through the Chain enum. Each chain includes configuration for chain IDs, network names, and block explorer URLs.

Accessing Chain Information

Import the Chain enum from the SDK:
from cowdao_cowpy.common.chains import Chain

# Access chain properties
chain = Chain.MAINNET
print(chain.chain_id)      # SupportedChainId.MAINNET
print(chain.name)          # "ethereum"
print(chain.explorer)      # "https://etherscan.io"

Supported Networks

Ethereum Mainnet

Chain ID: 1
Network Name: ethereum
Explorer: etherscan.io
Chain.MAINNET

Sepolia Testnet

Chain ID: 11155111
Network Name: sepolia
Explorer: sepolia.etherscan.io
Chain.SEPOLIA

Gnosis Chain

Chain ID: 100
Network Name: gnosis
Explorer: gnosisscan.io
Chain.GNOSIS

Arbitrum One

Chain ID: 42161
Network Name: arbitrum_one
Explorer: arbiscan.io
Chain.ARBITRUM_ONE

Base

Chain ID: 8453
Network Name: base
Explorer: basescan.org
Chain.BASE

Polygon

Chain ID: 137
Network Name: polygon
Explorer: polygonscan.com
Chain.POLYGON

Avalanche

Chain ID: 43114
Network Name: avalanche
Explorer: snowtrace.io
Chain.AVALANCHE

BNB Chain

Chain ID: 56
Network Name: bnb
Explorer: bscscan.com
Chain.BNB

Lens Network

Chain ID: 232
Network Name: lens
Explorer: explorer.lens.xyz
Chain.LENS

Chain Properties

Each Chain enum value provides three key properties:
Returns the SupportedChainId enum value representing the numeric chain identifier.
from cowdao_cowpy.common.chains import Chain

chain = Chain.MAINNET
chain_id = chain.chain_id  # SupportedChainId.MAINNET (value: 1)
Returns the network name as a string, useful for display and configuration purposes.
from cowdao_cowpy.common.chains import Chain

chain = Chain.GNOSIS
network_name = chain.name  # "gnosis"
Returns the block explorer URL for viewing transactions and addresses on the network.
from cowdao_cowpy.common.chains import Chain

chain = Chain.ARBITRUM_ONE
explorer_url = chain.explorer  # "https://arbiscan.io"

Usage Example

Here’s a complete example showing how to use chains when creating a swap:
import os
import asyncio
from dotenv import load_dotenv
from web3 import Account, Web3
from web3.types import Wei
from cowdao_cowpy.cow.swap import swap_tokens
from cowdao_cowpy.common.chains import Chain

load_dotenv()
PRIVATE_KEY = os.getenv("PRIVATE_KEY")
ACCOUNT = Account.from_key(PRIVATE_KEY)

# Define tokens and amount
SELL_TOKEN = Web3.to_checksum_address("0xbe72E441BF55620febc26715db68d3494213D8Cb")
BUY_TOKEN = Web3.to_checksum_address("0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14")
AMOUNT = Wei(5000000000000000000)

# Execute swap on Sepolia testnet
result = await swap_tokens(
    amount=AMOUNT,
    account=ACCOUNT,
    chain=Chain.SEPOLIA,  # Specify the chain
    sell_token=SELL_TOKEN,
    buy_token=BUY_TOKEN,
)

print(f"Order UID: {result.uid}")
print(f"Order URL: {result.url}")
When testing your integration, start with Chain.SEPOLIA to avoid risking real funds on mainnet.

Getting All Supported Chains

You can retrieve all supported chains using the SUPPORTED_CHAINS constant:
from cowdao_cowpy.common.chains import SUPPORTED_CHAINS

# Iterate through all supported chains
for chain in SUPPORTED_CHAINS:
    print(f"{chain.name}: Chain ID {chain.chain_id.value}")
The chain configuration is used internally by the SDK to determine API endpoints, contract addresses, and other network-specific settings.

Build docs developers (and LLMs) love