Overview

The SQL API allows you to create custom queries to pull real-time and historical onchain data from Base. In this quickstart, you will learn how to:
  • Read and use the tables in CDP’s curated schema.
  • Pull data from the Base blockchain with a SQL query. ​

Prerequisites

Sign in to the CDP Portal and create a CDP API key.

1. Write a query

Our example retrieves the most recent indexed event from the base.events table.
SELECT * FROM base.events LIMIT 1
The selected table and fields above can be found in our schema documentation.

2. Run a query

The SQL API /run endpoint accepts this query as a string value. Before running, replace $CLIENT_TOKEN with your CDP API key.
curl -H "Authorization: Bearer $CLIENT_TOKEN" -H "Content-Type: application/json" -X POST "https://api.cdp.coinbase.com/platform/v2/data/query/run" -d '{"sql": "SELECT * FROM base.events LIMIT 1"}'
After running the above, you should see a similar response to the following:
{
  "result": [
    {
      "action": "added",
      "address": "0x8c0075d087de9588ddf5c1441df39828d695bc2f",
      "block_hash": "0x8a337ac527a694e274e46d64bebda0bd40703e589b91f45e8ef3f24ff65ae44c",
      "block_number": "32430528",
      "block_timestamp": "2025-07-04T17:33:23Z",
      "event_name": "ANFEAssetAdded",
      "event_signature": "ANFEAssetAdded(uint256,address,uint8,address,uint256,uint256)",
      "log_index": "13",
      "parameter_types": {
        "adder": "address",
        "amount": "uint256",
        "assetType": "uint8",
        "contractAddress": "address",
        "licenseId": "uint256",
        "tokenId": "uint256"
      },
      "parameters": {
        "adder": "{0x6998723dfdd3ba214f8588b39608aed3a3208628 String}",
        "amount": "{{false [1]} UInt256}",
        "assetType": "{{false [2]} UInt256}",
        "contractAddress": "{0x674ddc6e324142713431a21d3e1bd0140cc700f7 String}",
        "licenseId": "{{false [581194974503308]} UInt256}",
        "tokenId": "{{false [4433908611]} UInt256}"
      },
      "topics": [
        "0x8bd9081c9d8f6eb8f0ffae42d72541d0141c0263b113a738f161eda334e6c2a9"
      ],
      "transaction_from": "0x6998723dfdd3ba214f8588b39608aed3a3208628",
      "transaction_hash": "0xbd85d2e6fd1eeebbfcd7cd45c041e6476497a7211469b99136324b81111f74c7",
      "transaction_to": "0x8c0075d087de9588ddf5c1441df39828d695bc2f"
    }
  ]
}
  • Schema reference: Familiarize yourself with our supported tables for SQL queries.