Querying Blockchain Data from Polymarket with Subgraphs on The Graph

·

Blockchain technology has revolutionized how data is stored and accessed, especially in decentralized applications like prediction markets. One of the most prominent platforms in this space is Polymarket, a blockchain-based prediction market built on Arbitrum. To extract meaningful insights from Polymarket’s onchain activity, developers and analysts rely on Subgraphs powered by The Graph Network—a decentralized protocol for indexing and querying blockchain data efficiently.

This guide walks you through how to query Polymarket's onchain data using GraphQL via Subgraphs, explore available schemas, use visual tools, authenticate with an API key, and integrate real-time data into your applications.


What Are Subgraphs and Why They Matter

Subgraphs are open APIs that allow developers to query blockchain data using GraphQL. Instead of scanning entire blockchains manually—a slow and resource-heavy process—Subgraphs index relevant events and store them in a queryable format.

👉 Discover how decentralized data indexing powers next-gen dApps

For platforms like Polymarket, where thousands of trades, redemptions, and market creations happen daily, Subgraphs unlock powerful analytics capabilities. You can track user behavior, monitor high-value payouts, analyze market trends, and more—all in real time.


Explore the Polymarket Subgraph on Graph Explorer

The easiest way to start querying Polymarket data is through the Graph Explorer, which hosts the official Polymarket Subgraph:

🔗 https://thegraph.com/explorer/subgraphs/Bx1W4S7kDVxs9gC3s2G6DS8kdNBJNVhMviCtin2DiBp?view=Query&chain=arbitrum-one

This interactive playground allows you to:

It’s ideal for both beginners learning GraphQL and experienced developers building data dashboards or trading bots.


Using the Visual Query Editor

The Graph Explorer includes a GraphiQL interface—a visual editor that simplifies crafting GraphQL queries. You can click through available fields instead of memorizing syntax.

Step-by-step: Building Your First Query

  1. Open the Polymarket Subgraph in Graph Explorer.
  2. Click on "Explore Schema" or use the autocomplete panel.
  3. Select entities such as redemptions, markets, or trades.
  4. Choose the fields you want returned (e.g., payout, redeemer, timestamp).
  5. Apply filters, sorting (orderBy, orderDirection), and limits (first).

This no-code approach accelerates development and reduces errors.


Example Query: Top 5 Highest Payouts on Polymarket

Want to see who’s cashing out big wins? Here’s a practical example:

{
  redemptions(orderBy: payout, orderDirection: desc, first: 5) {
    id
    payout
    redeemer
    timestamp
  }
}

Expected 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 in wei or scaled units—convert them based on token decimals for human-readable amounts.

This query reveals top earners, helping identify whale activity or popular resolved markets.


Understanding the Polymarket GraphQL Schema

The structure of available data is defined in the GraphQL schema, hosted on Polymarket’s GitHub:

🔗 https://github.com/Polymarket/polymarket-subgraph/blob/main/polymarket-subgraph/schema.graphql

Key entities include:

Each entity maps directly to smart contract events emitted on-chain, ensuring accuracy and transparency.


Accessing the Polymarket Subgraph Endpoint

To fetch data programmatically, use the public endpoint:

https://gateway.thegraph.com/api/{api-key}/subgraphs/id/Bx1W4S7kDVxs9gC3s2G6DS8kdNBJNVhMviCtin2DiBp

Replace {api-key} with your personal key from The Graph Studio.

👉 Learn how to build real-time blockchain analytics tools

This URL becomes the target for all HTTP POST requests carrying your GraphQL queries.


How to Get Your Free API Key

Follow these steps to authenticate and start querying:

  1. Visit https://thegraph.com/studio and connect your Web3 wallet.
  2. Navigate to API Keys at https://thegraph.com/studio/apikeys/.
  3. Click “Create API Key” and copy it securely.

💡 Good news: Every account gets 100,000 free queries per month—perfect for side projects, research, or MVPs.

Your key works across all subgraphs in The Graph ecosystem, not just Polymarket.


Additional Polymarket Subgraphs for Specialized Data

Beyond the main subgraph, several specialized ones offer deeper insights:

These enable advanced use cases like performance tracking, risk modeling, and sentiment analysis.


Querying Programmatically: Node.js Example

You can integrate Polymarket data into backend services or frontends using standard HTTP clients.

Here’s a working Node.js script using Axios:

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(JSON.stringify(data, null, 2));
  })
  .catch((error) => {
    console.error('Error fetching data:', error.response?.data || error.message);
  });

Replace YOUR_API_KEY with your actual key. This script fetches the first five positions held by users, including their associated conditions and outcome indices.


Core Keywords for SEO Optimization

To enhance search visibility and align with user intent, this article naturally integrates the following keywords:

These terms reflect common search patterns among developers, researchers, and crypto enthusiasts seeking actionable insights from decentralized platforms.


Frequently Asked Questions (FAQ)

Q: Is querying Polymarket data free?

Yes. With The Graph’s free tier, you get up to 100,000 queries per month at no cost. This is sufficient for most personal projects and small-scale analytics tools.

Q: Do I need to run my own node to use Subgraphs?

No. The Graph abstracts away infrastructure complexity. You interact with indexed data via HTTPS without managing nodes or syncing blockchains.

Q: Can I query historical data from Polymarket?

Absolutely. Subgraphs index data from contract deployment onward. You can retrieve trades, redemptions, or market creations going back years.

Q: Are there rate limits on queries?

While there’s no strict rate limiting under normal usage, excessive requests may be throttled. For heavy workloads, consider upgrading to a paid plan or caching results.

Q: How often is the data updated?

Subgraphs sync in near real-time—usually within seconds of a transaction being confirmed on Arbitrum.

Q: Can I build a dashboard with this data?

Yes! Many developers use this data to create live dashboards showing trending markets, top traders, payout histories, and more—using React, D3.js, or dashboard frameworks.


👉 Turn blockchain data into powerful insights—start querying today

By leveraging Subgraphs on The Graph Network, anyone can unlock the full potential of onchain data from platforms like Polymarket. Whether you're analyzing market trends, auditing payouts, or building a prediction market scanner, GraphQL makes it fast, reliable, and scalable.