Time
Time
Working with time on Cardano
Time
Cardano uses a slot-based time system. Each slot has a fixed duration (typically 1 second on mainnet), and transactions reference slots for validity ranges. Evolution SDK handles the conversion between Unix timestamps and slots automatically.
Key Concepts
| Concept | Description |
|---|---|
| Slot | A numbered time unit on the blockchain |
| Unix Time | Milliseconds since epoch (standard POSIX time) |
| Validity Range | Time window during which a transaction is valid |
| Slot Config | Network-specific mapping between slots and Unix time |
How It Works
When you call .setValidity({ from, to }), you provide Unix timestamps in milliseconds. The transaction builder converts these to slots using the network's slot configuration:
import { } from "@evolution-sdk/evolution"
const = ({
: "preprod",
: { : "blockfrost", : "https://cardano-preprod.blockfrost.io/api/v0", : ..! },
: { : "seed", : ..!, : 0 }
})
declare const : any
const = (.())
// Set validity: valid from now, expires in 5 minutes
// await client.newTx()
// .setValidity({ from: now, to: now + 300_000n })
// ...