Beginner5 min read
Edit on GitHub

First Request

Make your first API request and understand the response

Let's make a real API request and understand what comes back.

Choosing a Network

All examples in this guide use Mainnet endpoints. To use Preprod Testnet instead, simply add /preprod to the path:

NetworkOgmios Endpoint
Mainnethttps://api.nacho.builders/v1/ogmios
Preprodhttps://api.nacho.builders/v1/preprod/ogmios

Your API key works on both networks.

Understanding JSON-RPC

Nacho API uses the JSON-RPC 2.0 protocol. Every request has this structure:

{
  "jsonrpc": "2.0",
  "method": "methodName",
  "params": { },
  "id": "optional-request-id"
}
FieldRequiredDescription
jsonrpcYesAlways "2.0"
methodYesThe API method to call
paramsNoParameters for the method
idNoYour custom ID, returned in response

Query the Current Epoch

Let's query the current Cardano epoch:

curl -X POST https://api.nacho.builders/v1/ogmios \
-H "Content-Type: application/json" \
-H "apikey: YOUR_API_KEY" \
-d '{
  "jsonrpc": "2.0",
  "method": "queryLedgerState/epoch",
  "id": "my-first-request"
}'

Try It Live

Loading...

Understanding the Response

A successful response looks like:

{
  "jsonrpc": "2.0",
  "method": "queryLedgerState/epoch",
  "result": 523,
  "id": "my-first-request"
}
FieldDescription
jsonrpcProtocol version (always "2.0")
methodEchoes the method you called
resultThe query result (epoch number)
idYour request ID echoed back

Error Responses

If something goes wrong, you'll get an error object instead of result:

{
  "jsonrpc": "2.0",
  "error": {
    "code": -32600,
    "message": "Invalid request",
    "data": { "reason": "Missing 'method' field" }
  },
  "id": null
}

Common error codes:

CodeMeaning
-32700Parse error (invalid JSON)
-32600Invalid request
-32601Method not found
-32602Invalid params
-32603Internal error

Query with Parameters

Some methods require parameters. Let's query protocol parameters:

curl -X POST https://api.nacho.builders/v1/ogmios \
-H "Content-Type: application/json" \
-H "apikey: YOUR_API_KEY" \
-d '{
  "jsonrpc": "2.0",
  "method": "queryLedgerState/protocolParameters"
}'

What's Next?

Now that you understand the basics:

Was this page helpful?