ERCs
ERC-6372 — Contract Clock
Lets a contract declare whether its time-sensitive logic uses block numbers or unix timestamps. Voting contracts (ERC-5805), vesting schedules, and time-locked governance all consume this.
import { eip155_1 } from "@ethernauta/chain/eip155-1";
import { AddressSchema } from "@ethernauta/core";
import { clock, CLOCK_MODE } from "@ethernauta/erc/6372";
import { eth_call } from "@ethernauta/eth";
import { contract, create_reader, encode_chain_id, http } from "@ethernauta/transport";
import { parse } from "valibot";
const CHAIN_ID = encode_chain_id({ namespace: "eip155", reference: eip155_1.chainId });
const reader = create_reader([
{ chainId: CHAIN_ID, transports: [http("https://ethereum-rpc.publicnode.com")] },
]);
const governor = parse(AddressSchema, "0x0000000000000000000000000000000000000000");
const ctx = contract({ chain_id: CHAIN_ID, to: governor });
const now_callable = clock()(ctx);
const mode_callable = CLOCK_MODE()(ctx);
const now_bytes = await eth_call([{ to: now_callable.to, input: now_callable.data }])(reader({ chain_id: CHAIN_ID }));
const mode_bytes = await eth_call([{ to: mode_callable.to, input: mode_callable.data }])(reader({ chain_id: CHAIN_ID }));
const now = now_callable.decode(now_bytes);
const mode = mode_callable.decode(mode_bytes);
// e.g. "mode=blocknumber&from=default" or "mode=timestamp&from=default" Surface
| Method | Shape | Purpose |
|---|---|---|
clock() | Callable<Uint48> | Current timepoint (block or timestamp). |
CLOCK_MODE() | Callable<string> | Declaration string. |
See also
- ERC-5805 — the primary consumer.