Time & Clock
The Clock sysvar provides slot, epoch, and unix_timestamp for time-based rules: expiries, vesting cliffs, and rate limits. Slots are discrete; timestamps are wall-clock approximations.
Search across all documentation pages
The Clock sysvar provides slot, epoch, and unix_timestamp for time-based rules: expiries, vesting cliffs, and rate limits. Slots are discrete; timestamps are wall-clock approximations.
let clock = Clock::get()?;
if clock.unix_timestamp > deadline { return Err(ProgramError::InvalidAccountData); }When to reach for this:
pub fn assert_not_expired(deadline: i64) -> Result<(), ProgramError> {
let now = Clock::get()?.unix_timestamp;
if now > deadline { return Err(ProgramError::InvalidAccountData); }
Ok(())
}What this demonstrates:
| Field | Use |
|---|---|
| slot | Leader schedule relative |
| unix_timestamp | Human expiry |
| epoch | Staking periods |
Validators have bounded timestamp drift - design grace periods.
// Store i64 deadline at init from client or admin.| Alternative | Use When | Don't Use When |
|---|---|---|
| Off-chain cron | Not binding | On-chain Clock |
| Slot-based only | Predictable | User confusion |
| Oracle time | Overkill | DeFi specific |
Known constant - Sysvar::get.
Do not accept passed account - use get.
Before 1970 rare - reject.
store start + duration.
Compute unlocked = f(now).
Wrapper.
LiteSVM warp clock.
Small - not exploitable large.
Different sysvar.
last_action_ts in account.
Anyone can call expire ix.
Clock layout stable.
Stack versions: This page was written for Agave 4.1.1, Solana CLI 3.0.10, Anchor 0.32.1, anchor-lang 0.32.1, Rust 1.91.1, @solana/kit 7.0.0, Surfpool 0.12.0, and LiteSVM 0.6.x.
Reviewed by Chris St. John·Last updated Jul 16, 2026