The decentralized finance (DeFi) and blockchain-based prediction market landscape is rapidly evolving, with platforms like Polymarket at the forefront. As onchain activity grows, so does the need for efficient, reliable ways to access and analyze data. This is where The Graph Network comes in — a decentralized protocol that indexes and enables querying of blockchain data through open APIs called subgraphs.
In this guide, we’ll explore how to query Polymarket’s onchain data using GraphQL via subgraphs on The Graph. Whether you're a developer building analytics tools, a trader analyzing market behavior, or just curious about blockchain data retrieval, this walkthrough will equip you with practical knowledge and real-world examples.
👉 Discover how to turn blockchain data into actionable insights with powerful query tools.
Exploring the Polymarket Subgraph on The Graph Explorer
The easiest way to start interacting with Polymarket’s blockchain data is through the Graph Explorer, The Graph’s user-friendly interface for testing and running queries.
You can access the Polymarket subgraph directly on The Graph Explorer, where you'll find an interactive playground. This environment allows you to experiment with different queries in real time, see structured responses, and understand the available data schema without writing a single line of code.
This subgraph captures key events from Polymarket’s smart contracts on Arbitrum, including trades, redemptions, positions, and market outcomes — all queryable via GraphQL.
Using the Visual Query Editor
The Graph Explorer includes a visual query editor powered by GraphiQL, which simplifies the process of building GraphQL queries. You can click through available fields and nested objects to construct your request logically.
Here’s how to get started:
- Open the Polymarket subgraph in Graph Explorer.
- Use the explorer panel to expand entities like
redemptions,markets, orpositions. - Select the fields you want to retrieve (e.g.,
payout,redeemer,timestamp). - Click “Run” to execute the query and view JSON results instantly.
This visual approach lowers the barrier for newcomers while still offering full flexibility for advanced users.
Example Query: Get Top 5 Highest Payouts
One common use case is identifying large redemption events — useful for tracking whale activity or validating payout trends.
{
redemptions(orderBy: payout, orderDirection: desc, first: 5) {
payout
redeemer
id
timestamp
}
}This query fetches the top five redemptions sorted by payout amount in descending order.
Sample Output
{
"data": {
"redemptions": [
{
"id": "0x8fbb68b7c0cbe9aca6024d063a843a23d046b5522270fd25c6a81c511cf517d1_0x3b",
"payout": "6274509531681",
"redeemer": "0xfffe4013adfe325c6e02d36dc66e091f5476f52c",
"timestamp": "1722929672"
},
{
"id": "0x2b2826448fcacde7931828cfcd3cc4aaeac8080fdff1e91363f0589c9b503eca_0x7",
"payout": "2246253575996",
"redeemer": "0xfffe4013adfe325c6e02d36dc66e091f5476f52c",
"timestamp": "1726701528"
}
]
}
}Note: Payout values are typically returned in wei or base units; you may need to convert them to human-readable formats (e.g., dividing by 1e18).
Understanding Polymarket’s GraphQL Schema
The structure of available data is defined in the GraphQL schema, which acts as a contract between client and server. The schema for the Polymarket subgraph is open-source and hosted on GitHub.
Key entities include:
Market: Contains details like question, outcome, resolution status.Position: Represents user holdings in specific outcomes.Trade: Records individual trades with prices and volumes.Redemption: Tracks when users claim winnings.
Each entity exposes fields and relationships that can be queried recursively, enabling deep analysis of user behavior and market dynamics.
Accessing the Polymarket Subgraph Endpoint
To integrate this data into your application, use the official endpoint:
https://gateway.thegraph.com/api/{api-key}/subgraphs/id/Bx1W4S7kDVxs9gC3s2G6DS8kdNBJNVhMviCtin2DiBpReplace {api-key} with your personal API key from The Graph Studio. This endpoint returns JSON responses over HTTPS, making it compatible with virtually any programming language or framework.
👉 Learn how to build real-time data dashboards using decentralized APIs.
How to Get Your API Key
To make programmatic requests, follow these steps:
- Visit The Graph Studio and connect your Ethereum-compatible wallet.
- Navigate to the API Keys page.
- Generate a new API key — no credit card required.
You receive 100,000 free queries per month, ideal for side projects, prototypes, or small-scale analytics tools. The key works across all public subgraphs in The Graph ecosystem, not just Polymarket.
Additional Polymarket Subgraphs
Beyond the main subgraph, several specialized variants exist for targeted analysis:
- Polymarket Main Subgraph – Core market and trade data.
- Polymarket Activity (Polygon) – Tracks user interactions on Polygon.
- Profit & Loss Subgraph – Calculates realized gains/losses per user.
- Open Interest Subgraph – Monitors total locked value across markets.
These allow developers to create niche tools such as performance trackers, risk models, or sentiment dashboards.
Querying Programmatically: Node.js Example
You can fetch data directly in your apps using HTTP clients like Axios. Here's a working example in Node.js:
const axios = require('axios');
const graphqlQuery = `
{
positions(first: 5) {
condition
outcomeIndex
}
}
`;
const queryUrl = 'https://gateway.thegraph.com/api/YOUR_API_KEY/subgraphs/id/Bx1W4S7kDVxs9gC3s2G6DS8kdNBJNVhMviCtin2DiBp';
const graphQLRequest = {
method: 'post',
url: queryUrl,
data: { query: graphqlQuery },
};
axios(graphQLRequest)
.then((response) => {
const data = response.data.data;
console.log(data);
})
.catch((error) => {
console.error('Error fetching data:', error);
});Replace YOUR_API_KEY with your actual key. This script retrieves the first five position records, showing which market condition and outcome index each relates to.
Core Keywords
- Polymarket blockchain data
- The Graph Network
- Subgraphs
- GraphQL queries
- Onchain analytics
- Decentralized APIs
- Polymarket subgraph
- Querying blockchain
Frequently Asked Questions (FAQ)
What is a subgraph in The Graph Network?
A subgraph is a decentralized API that defines how blockchain data should be indexed and queried. It maps smart contract events to a GraphQL schema, allowing developers to retrieve structured data efficiently.
Can I query historical Polymarket trades?
Yes. The Polymarket subgraph includes historical trade events. Use the trades entity with filters like market, trader, or timestamp to retrieve past transactions.
Is querying the subgraph free?
Yes, up to 100,000 queries per month are free with a registered API key from The Graph Studio. High-volume applications can upgrade for additional capacity.
How often is the data updated?
Data is indexed in near real-time as blocks are confirmed on Arbitrum. Delays are typically under a minute, making it suitable for live dashboards and monitoring tools.
Do I need to run my own indexer?
No. Public subgraphs like Polymarket’s are hosted and maintained by The Graph Network. You only need an API key to query them — no infrastructure required.
Can I build a frontend dApp using this data?
Absolutely. Many developers use subgraphs to power decentralized applications (dApps), including trading interfaces, analytics platforms, and portfolio trackers.
👉 Start building your own blockchain-powered app today with seamless data access.
With powerful tools like The Graph and accessible subgraphs for platforms like Polymarket, anyone can unlock valuable insights from onchain activity. Whether you're analyzing market trends or building the next generation of Web3 applications, structured blockchain querying has never been easier.