Skip to Content
DocumentationRpcGet Current Slot

Get Current Slot

The getCurrentSlot function retrieves the current slot the node is processing. Slots are Solana’s unit of time, with each slot representing approximately 400ms.

Usage

const slot = await connection.getCurrentSlot();

Parameters

  • commitment: Commitment (optional) - Confirmation level to use (default: “finalized”)
    • "processed" - Processed by current node (most recent)
    • "confirmed" - Confirmed by supermajority of the cluster
    • "finalized" - Confirmed by supermajority and unlikely to revert

Returns

Returns a Promise<bigint> - The current slot number.

Example

// Get the current slot with default commitment const slot = await connection.getCurrentSlot(); console.log(`Current slot: ${slot}`); // Get with specific commitment level const processedSlot = await connection.getCurrentSlot("processed"); console.log(`Current slot (processed): ${processedSlot}`); const finalizedSlot = await connection.getCurrentSlot("finalized"); console.log(`Current slot (finalized): ${finalizedSlot}`); // Calculate elapsed time since a transaction const transactionSlot = 123456789n; const currentSlot = await connection.getCurrentSlot(); const slotsDiff = currentSlot - transactionSlot; const secondsElapsed = Number(slotsDiff) * 0.4; // Approximate console.log(`Transaction was ${slotsDiff} slots ago (~${secondsElapsed.toFixed(1)}s)`);

Use Cases

  • Monitoring network progression
  • Calculating time elapsed since a transaction
  • Checking if the network is producing blocks
  • Implementing time-based logic in programs

Notes

  • Each slot represents approximately 400 milliseconds
  • Not every slot contains a block (some slots may be skipped)
  • Using “processed” commitment gives the most recent slot
  • Using “finalized” commitment gives a slightly older but more reliable slot
  • The slot number is always increasing (unless the network experiences issues)
Last updated on