Skip to main content
The SubgraphApi provides a TypeScript client for querying historical trading data, volume statistics, and protocol metrics from CoW Protocol subgraphs across multiple chains.

Installation

Features

  • SubgraphApi Client - Main client for querying CoW Protocol subgraphs
  • Pre-built Queries - Common queries for totals, volume, and statistics
  • Multi-chain Support - Ethereum, Gnosis Chain, Arbitrum, Base, and Sepolia
  • Type-safe Responses - Fully typed GraphQL responses
  • Custom Query Support - Run any GraphQL query with full type safety

Constructor

SubgraphApi

string
required
TheGraph API key from TheGraph Studio
SubgraphApiOptions
Optional configuration

Methods

getTotals

Get overall protocol statistics including tokens, orders, traders, settlements, volume, and fees.
string
Total number of unique tokens traded
string
Total number of orders placed
string
Total number of unique traders
string
Total number of settlements
string
Total trading volume in USD
string
Total fees collected in USD

getLastDaysVolume

Get historical volume data for a specified number of days.
number
required
Number of days to query (e.g., 7, 30)
DailyTotal[]
Array of daily volume totals

getLastHoursVolume

Get historical volume data for a specified number of hours.
number
required
Number of hours to query (e.g., 24, 48)
HourlyTotal[]
Array of hourly volume totals

runQuery

Execute a custom GraphQL query with full type safety.
string | DocumentNode
required
GraphQL query string or parsed DocumentNode
object
Optional query variables

Usage Examples

Basic Setup

Query Protocol Metrics

Query Historical Data

Custom Queries

Multi-Chain Queries

Supported Chains

The SubgraphApi supports the following networks:
  • Ethereum Mainnet (1)
  • Gnosis Chain (100)
  • Arbitrum One (42161)
  • Base (8453)
  • Sepolia Testnet (11155111)

API Key Requirements

To use this package, you need a Graph API key:
  1. Go to TheGraph Studio
  2. Create a new API key
  3. Use the API key when initializing SubgraphApi
Keep your API key secure and never expose it in client-side code. Consider using environment variables.