Solana Rental Escrow is a real-world rental workflow implemented as an Anchor program. It lets an item owner list a physical asset, a renter escrow rent plus a security deposit, and both sides complete pickup, return, and settlement on-chain.
This repository was built for the Superteam Earn challenge: "Build everyday real-world systems as on-chain Rust programs."
The MVP focuses on short-term peer-to-peer rentals, such as tools, camera gear, sports equipment, or event hardware.
Core flow:
- Owner creates a listing with an item hash, daily price, security deposit, and max rental days.
- Renter reserves the item by paying rent plus deposit into the listing escrow.
- Owner approves pickup, starting the rental window.
- Renter marks the item returned.
- Owner settles, keeping rent and optionally part of the deposit for damage.
- Either party can cancel before pickup, refunding the renter.
- Owner can claim the full escrow if an active rental becomes overdue past the grace window.
Program id:
82snC2byh3kq8w2p9h4nXYtx6xtZKvnNVC2WzPVsmKfF
Main file:
programs/rental-escrow/src/lib.rs
Instructions:
create_listingreserveapprove_pickupmark_returnedsettlecancel_reservationclaim_overdueclose_listing
Events are emitted for listing creation, reservation, pickup, return, settlement, cancellation, and overdue claim. That makes the program straightforward to index into a dashboard later.
stateDiagram-v2
[*] --> Listed
Listed --> Reserved: reserve
Reserved --> Active: approve_pickup
Reserved --> Cancelled: cancel_reservation
Active --> Returned: mark_returned
Active --> Settled: claim_overdue
Returned --> Settled: settle
Listed --> [*]: close_listing
Cancelled --> [*]: close_listing
Settled --> [*]: close_listing
Prerequisites:
- Rust
- Node.js
- Solana CLI
- Anchor CLI 0.31.x, preferably through AVM
Install dependencies:
npm installRun host-side Rust tests:
cargo test --workspaceRun TypeScript compile check:
npx tsc --noEmitRun full Anchor localnet tests:
anchor testConfigure wallet and RPC:
export ANCHOR_PROVIDER_URL=https://api.devnet.solana.com
export ANCHOR_WALLET=~/.config/solana/id.jsonBuild and deploy:
anchor build
anchor deploy --provider.cluster devnetCreate a listing:
npm run cli -- create --listing-id 1 --item "bosch drill serial 42" --daily-sol 0.1 --deposit-sol 0.5 --max-days 7Derive the listing PDA:
npm run cli -- derive --owner <OWNER_PUBKEY> --listing-id 1Reserve as renter:
npm run cli -- reserve --owner <OWNER_PUBKEY> --listing-id 1 --days 2Approve pickup as owner:
npm run cli -- approve --listing <LISTING_PDA>Mark returned as renter:
npm run cli -- return --listing <LISTING_PDA>Settle as owner:
npm run cli -- settle --listing <LISTING_PDA> --renter <RENTER_PUBKEY> --keep-deposit-sol 0.05See scripts/devnet-demo.md for the exact transaction capture checklist.
- Escrow is held as lamports in the listing account, with
escrow_lamportstracked separately from the account rent-exempt balance. - Settlement checks that owner and renter payouts exactly match tracked escrow.
- The owner cannot rent their own item.
- Deposit claims cannot exceed the paid deposit.
- Reservations can only be cancelled before pickup.
- Overdue claims require the active rental to exceed its due timestamp plus a one-day grace period.
Verified in this workspace:
cargo test --workspace
npx tsc --noEmit
Full anchor test and devnet deployment require Solana CLI plus Anchor CLI. This Windows workspace currently has Rust and Node but does not have Solana CLI or a working Windows Anchor binary.