queryLedgerState/tip

Query the current ledger tip (latest block)

Query the current tip of the ledger - the most recently applied block. This is essential for determining the current state of the blockchain.

Request

{
  "jsonrpc": "2.0",
  "method": "queryLedgerState/tip"
}

No parameters required.

Loading...

Response

{
  "jsonrpc": "2.0",
  "method": "queryLedgerState/tip",
  "result": {
    "slot": 123456789,
    "id": "8e8c93fb4a7c7e5a1a3e5f9b2c4d6e8f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d"
  }
}

Response Fields

FieldTypeDescription
slotnumberCurrent slot number
idstringBlock hash (64 hex characters)

Code Examples

async function getLedgerTip() {
const response = await fetch('https://api.nacho.builders/v1/ogmios', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'apikey': process.env.NACHO_API_KEY
  },
  body: JSON.stringify({
    jsonrpc: '2.0',
    method: 'queryLedgerState/tip'
  })
});

const { result } = await response.json();
return result;
}

const tip = await getLedgerTip();
console.log('Current slot:', tip.slot);
console.log('Block ID:', tip.id);

Slot to Time Conversion

Convert slot numbers to real-world timestamps:

// Mainnet Shelley start: slot 4492800, epoch 208
// 2020-07-29 21:44:51 UTC
const SHELLEY_START_SLOT = 4492800;
const SHELLEY_START_TIME = new Date('2020-07-29T21:44:51Z').getTime();
const SLOT_LENGTH_MS = 1000; // 1 second per slot

function slotToTime(slot) {
  const slotsSinceShelley = slot - SHELLEY_START_SLOT;
  return new Date(SHELLEY_START_TIME + (slotsSinceShelley * SLOT_LENGTH_MS));
}

function timeToSlot(date) {
  const msSinceShelley = date.getTime() - SHELLEY_START_TIME;
  return SHELLEY_START_SLOT + Math.floor(msSinceShelley / SLOT_LENGTH_MS);
}

// Example
const tip = await getLedgerTip();
console.log('Block time:', slotToTime(tip.slot).toISOString());

The ledger tip reflects the last fully applied block. For real-time block monitoring, use chain synchronization instead of polling this endpoint.

ledgerState/tip vs queryNetwork/tip

MethodDescription
queryLedgerState/tipLatest block applied to ledger state
queryNetwork/tipLatest block known to the network layer

These are usually the same, but queryNetwork/tip may be slightly ahead during block propagation.

Use Cases

  • Transaction building - Calculate TTL (Time To Live) based on current slot
  • Sync status - Check if your application is up to date
  • Chain intersection - Use as starting point for chain synchronization
  • Epoch calculation - Determine current epoch from slot number

Full Ogmios API Reference

Was this page helpful?