How a key works
A small contract sells keys. A gateway checks them before anything opens.
The lifecycle
- 01
Rule
Price, token and what a unit buys.
- 02
Payment
Units × price, in one transaction.
- 03
Key
Holder, start, end or uses, on-chain.
- 04
Check
The gateway reads the key on-chain.
- 05
Unlock
A lock opens, or content appears.
- 06
Expiry
Time or uses run out; it stays shut.
renew: Expiry → Payment
The rule
One per gate. It never changes a key already sold.
| Field | Meaning | Riverside court 2 |
|---|---|---|
| mode | time, uses or forever | uses |
| price | Price of one unit | 15 |
| token | Token the contract accepts | tUSDC |
| unit | Minutes or uses per unit | 10 entries |
| maxUnits | Most units in one purchase | 2 |
| action | Gateway action after a check | webhook gate.unlock |
What the contract records
Each purchase mints a key and emits an event.
Renewal extends from the later of now and the current end.
Show the contract events
event KeyPurchased(
uint256 indexed tokenId,
bytes32 indexed gateId,
address indexed holder,
uint64 start,
uint64 end, // 0 for metered and forever keys
uint32 uses, // 0 for time and forever keys
uint256 paid
);
event KeyUsed(uint256 indexed tokenId, uint32 usesLeft);
event KeyRenewed(uint256 indexed tokenId, uint64 end, uint32 uses, uint256 paid);
function accessOf(uint256 tokenId)
external view
returns (bytes32 gateId, address holder, uint64 end, uint32 usesLeft, bool forever);What the gateway does
For every unlock, it:
- 1Finds the key and checks its gate.
- 2Refuses it if paused, expired or used up.
- 3Spends one entry, for metered keys.
- 4Opens the lock, or reveals the content.
- 5Logs the check and the result.
Show the webhook payload
Webhook sent to a court gate
POST https://gates.harbourview-parks.example/riverside-2/unlock
X-GatePay-Signature: t=1759152131,v1=6f0c…e41a
{
"event": "gate.unlock",
"gate": "riverside-court",
"key": "GP-4K7Q-2M",
"holder": "0x5ae1…c3B9",
"validUntil": "2026-09-29T16:02:11Z",
"block": 6512344,
"pin": "482913",
"holdOpenSeconds": 10
}Signed; the lock ignores unsigned or stale calls.
Where it plugs in
The gateway talks to hardware you can already buy, and to your own code.
Physical
Smart locks
Wi-Fi or Bluetooth locks get a PIN or an app unlock for the key's lifetime.
Offline keypads
Time-bound PINs, computed without a network. Good for a fenced court.
NFC and QR readers
Turnstiles and gates read a phone tap or a code.
Relays
A small controller switches a gate motor or court lights.
Digital
Web SDK
One call checks the key and unlocks content in your page.
Webhooks
Signed calls to your server after every check.
The SDK, in one call
import { GatePay } from "@gatepay/sdk"
const gatepay = new GatePay({ chain: "base-sepolia" })
// Checks the visitor's key on-chain, then reveals the content.
const access = await gatepay.unlock("rooftop-session", { wallet })
if (access.ok) player.play(access.stream)Illustrative: in this demo, the SDK and the hardware are simulated.
Where it can go next
- Per-minute pricing for streams.
- One key for several gates, like every court in a park.
- Lights that switch on only while a court key is live.
- Transferable keys, when the owner allows resale.
