queryLedgerState_epoch - Cardno

This method returns the current epoch number of the ledger. Epochs group slots into the units used for reward and parameter cycles.

Parameters

  • none

Request

bashcurl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "queryLedgerState/epoch",
    "id": "getblock.io"
}'

example.js

javascriptconst response = await fetch(
    'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
    {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({"jsonrpc": "2.0", "method": "queryLedgerState/epoch", "id": "getblock.io"})
    }
);
console.log(await response.json());

example.py

pythonimport requests

response = requests.post(
    'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
    headers={'Content-Type': 'application/json'},
    json={"jsonrpc": "2.0", "method": "queryLedgerState/epoch", "id": "getblock.io"}
)

print(response.json())

Response

json{
    "jsonrpc": "2.0",
    "method": "queryLedgerState/epoch",
    "result": 507,
    "id": "getblock.io"
}

Response Parameters

FieldTypeDescription
resultintegerCurrent epoch number

Use Cases

  • Reward Cycles: Align reward calculations to epoch boundaries
  • Parameter Windows: Detect when protocol parameters may change
  • Scheduling: Trigger epoch-based jobs
  • Display: Show the current epoch on a dashboard

Error Handling

Error CodeMessageDescription
-32602Invalid paramsA required field is missing or has the wrong type
-32000Query unavailableThe query is not available in the current ledger era
-32603Internal errorThe node failed to answer the query