GraphQL API

Query Cardano blockchain data with flexible GraphQL queries

Query the Cardano blockchain using flexible GraphQL queries. The GraphQL API provides access to all indexed blockchain data including blocks, transactions, UTxOs, stake pools, and more.

Base URLs

Mainnet

https://api.nacho.builders/v1/graphql

Preprod Testnet

https://api.nacho.builders/v1/preprod/graphql

Your API key works on both networks. Switch between Mainnet and Preprod by changing the URL.

Authentication

Include your API key in the apikey header:

curl -X POST https://api.nacho.builders/v1/graphql \
  -H "Content-Type: application/json" \
  -H "apikey: YOUR_API_KEY" \
  -d '{"query": "{ block(limit: 1) { block_no } }"}'

Interactive Playground

Try GraphQL queries directly in your browser:

Loading...

Playground format: Enter your GraphQL query directly in the QUERY panel (not wrapped in JSON). Put variables in the VARIABLES panel as a JSON object. Use the Examples dropdown to see properly formatted queries.

HTTP Request Format

When making direct HTTP requests (e.g., with curl, fetch, or your application), send a POST request with a JSON body:

{
  "query": "query { block(limit: 1) { block_no epoch_no } }",
  "variables": {}
}

With Variables

{
  "query": "query GetBlock($num: bigint!) { block(where: {block_no: {_eq: $num}}) { block_no hash } }",
  "variables": { "num": 12880000 }
}

The JSON format above is for HTTP requests, not for the playground. In the playground, put just the query in the QUERY panel.

Available Types

The GraphQL schema exposes all DB-Sync indexed data. Key types include:

Blockchain Data

TypeDescription
blockBlock information including slot, epoch, hash, transactions
txTransaction data with inputs, outputs, metadata
tx_outTransaction outputs (UTxOs)
tx_inTransaction inputs
datumPlutus datums
scriptScript definitions
redeemerScript redeemers

Staking

TypeDescription
pool_hashStake pool identifiers
pool_updatePool registration/update certificates
pool_metadata_refPool metadata URLs
stake_addressStaking addresses
epoch_stakeStake distribution per epoch

Epochs & Protocol

TypeDescription
epochEpoch summary data
ada_potsADA distribution per epoch

Example Queries

Get Latest Block

query LatestBlock {
  block(limit: 1, order_by: {id: desc}) {
    block_no
    epoch_no
    slot_no
    time
    tx_count
    hash
  }
}

Get Block by Number

query BlockByNumber($blockNo: Int!) {
  block(where: {block_no: {_eq: $blockNo}}) {
    block_no
    epoch_no
    slot_no
    time
    tx_count
    hash
  }
}

Get Current Epoch Info

query CurrentEpoch {
  epoch(limit: 1, order_by: {no: desc}) {
    no
    start_time
    end_time
    blk_count
    tx_count
    fees
    out_sum
  }
}

Get Recent Pool Updates

query RecentPoolUpdates($limit: Int) {
  pool_update(limit: $limit, order_by: {id: desc}) {
    pledge
    margin
    fixed_cost
    active_epoch_no
    vrf_key_hash
  }
}

Filtering and Pagination

Where Clauses

Filter results using comparison operators:

query RecentLargeBlocks {
  block(
    where: {
      tx_count: {_gt: 100},
      time: {_gt: "2024-01-01"}
    }
    limit: 10
    order_by: {block_no: desc}
  ) {
    block_no
    tx_count
    time
  }
}

Available Operators

OperatorDescription
_eqEqual to
_neqNot equal to
_gtGreater than
_gteGreater than or equal
_ltLess than
_lteLess than or equal
_inIn array
_ninNot in array
_likePattern match (use %)
_ilikeCase-insensitive pattern match
_is_nullIs null check

Ordering

query OrderedBlocks {
  block(order_by: {block_no: desc}, limit: 10) {
    block_no
    time
  }
}

Pagination

Use limit and offset for pagination:

query PaginatedBlocks($offset: Int!, $limit: Int!) {
  block(
    order_by: {block_no: desc}
    limit: $limit
    offset: $offset
  ) {
    block_no
    hash
  }
}

Rate Limits

TierRate LimitQuery Depth
FREE10 req/sMax 3 levels
PAID100 req/sMax 10 levels

Complex queries with deep nesting may be rejected. If you need complex aggregations, consider using multiple simpler queries.

Error Handling

GraphQL returns errors in the errors array:

{
  "errors": [
    {
      "message": "field 'invalid_field' not found in type: 'block'",
      "extensions": {
        "path": "$.query",
        "code": "validation-failed"
      }
    }
  ]
}

Common Errors

ErrorCauseSolution
field not foundInvalid field nameCheck schema for valid fields
validation-failedQuery syntax errorVerify GraphQL syntax
rate limit exceededToo many requestsAdd delays between requests

Best Practices

  1. Request only needed fields - Don't select *, specify exact fields
  2. Use variables - Parameterize queries for reuse and caching
  3. Paginate large results - Use limit and offset for large datasets
  4. Avoid deep nesting - Keep query depth under 5 levels when possible
  5. Cache responses - Cache immutable data like historical blocks

Hasura GraphQL Query Documentation

Was this page helpful?