How to Use getSlot
Learn getSlot use cases, code examples, request parameters, response structure, and tips.
The getSlot
RPC method returns the current slot that the RPC node considers to have reached a specific commitment level. This is a fundamental method for understanding the current state of the blockchain as perceived by the node.
Common Use Cases
- Getting Current Network Progress: Determine the most recent slot processed or confirmed by the node.
- Node Synchronization Check: Comparing the slot from different nodes can give an indication of their synchronization status.
- Timestamping Operations: Using the current slot as a reference point for operations or for understanding the age of certain data.
- Input for Other RPC Calls: Some RPC methods might use a slot number as a reference point.
Request Parameters
This method takes an optional configuration object as its first parameter:
options
(object
, optional): An optional configuration object with the following fields:commitment
(string
, optional): Specifies the commitment level for the query. Supported values arefinalized
,confirmed
, orprocessed
. If omitted, the default commitment of the RPC node is used (usuallyfinalized
).processed
: The node will query its most recent slot. Note that this slot may not be confirmed by the cluster yet and could potentially be skipped.confirmed
: The node will query the most recent slot that has been voted on by a supermajority of the cluster.finalized
: The node will query the most recent slot confirmed by the supermajority of the cluster as having reached maximum lockout (cannot be rolled back).
minContextSlot
(number
, optional): The minimum slot that the request can be evaluated at. This sets the minimum slot for the node’s context. If the node’s state is older than this slot, it may return an error or a slot number that reflects its current (older) state relative to this minimum.
Response Structure
The result
field of the JSON-RPC response is a single u64
(unsigned 64-bit integer) representing the current slot number according to the specified commitment level.
Example Response:
Examples
1. Get Current Slot (Default Commitment)
This example fetches the current slot using the node’s default commitment level (usually finalized
).
2. Get Current Slot with a Specific Commitment
This example fetches the current slot that has reached confirmed
commitment.
Developer Tips
- Commitment Matters: The returned slot number heavily depends on the
commitment
level specified. Refer to Solana Commitment Levels for detailed information.processed
will be the highest (most recent) slot the node is aware of, whilefinalized
will be an older slot that is confirmed by the entire network. Choose the commitment level appropriate for your use case’s need for data finality. - Node Variability: Different RPC nodes might return slightly different slot numbers for the same commitment level due to network propagation delays or their own processing state. This is especially true for
processed
andconfirmed
levels. minContextSlot
: This parameter ensures that the node processing your request has reached at least theminContextSlot
. If the node is behind this slot, the behavior might vary (e.g., an error or the node’s current highest slot which is less thanminContextSlot
). It’s generally used in advanced scenarios where you need to ensure a query is made against a sufficiently recent state.
getSlot
is a simple yet essential method for interacting with the Solana blockchain and understanding its current progression.