Free quote
SleepFi - sleep-to-earn app on Solana
Solana
Anchor
React Native
Health Connect
DeFi
Sleep-to-Earn
Mobile Wallet Adapter
Expo
Smart Contract

SleepFi - sleep-to-earn app on Solana

Stake SOL on your sleep. Sleep 7h+. Earn rewards.

Client

Spark Hackathon / Solana Seeker

Industry

Blockchain / Health / DeFi

Scope of work

Mobile App + Smart Contract (Anchor)

Project duration

1 week

Project overview

SleepFi is a mobile app built for the Spark hackathon (Solana Seeker). The concept is simple: you stake SOL betting that you will sleep at least 7 hours every night for a week. Sleep data is pulled automatically from Android Health Connect (e.g. Sleep as Android) - there is no way to fake it manually. If you complete the challenge, you get your stake back plus a proportional share of the failed stakes pool. The entire mechanism runs through an Anchor smart contract on Solana - even the app creator cannot withdraw funds from the escrow.

The challenge

Building a sleep-to-earn app that is truly trustless - not just with a wallet login, but with real on-chain escrow - required solving several problems simultaneously.

Trustless escrow

SOL must be locked in a PDA controlled by the program, not in the creator's wallet. Users need a guarantee that nobody can run away with their money. Anchor program with 6 instructions and 3 PDA types (Pool, ChallengeEscrow, UserState).

Oracle pattern

Sleep data comes from Health Connect on Android, but must be recorded on-chain. The backend acts as an oracle - signing submit_sleep and complete/fail_challenge transactions with the treasury key, but has no access to escrow funds.

Mobile Wallet Adapter

On mobile there are no browser extension wallets. Integration with Phantom/Solflare via MWA (solana-mobile/mobile-wallet-adapter-protocol) requires manually building instructions with discriminators from the IDL - the Anchor.Program class is not compatible with MWA.

Health Connect integration

Reading sleep data from Android Health Connect (react-native-health-connect). Filtering sessions <30min and >12h, time window 6PM-2PM, server-side validation. No manual entry possible - only automatic import from sleep tracking apps.

Our solution

Full-stack MVP: Anchor smart contract on Solana, backend API on Vercel, React Native mobile app with Expo.

1

Anchor program - 6 instructions, 3 PDAs

Solana program handling: initialize_pool, start_challenge (lock SOL in escrow PDA), submit_sleep (oracle), complete_challenge (return stake + reward), fail_challenge (transfer to Pool PDA), claim_reward. Deployed on devnet: Gq6HZCUkXhznL8BBfEVXwnB4BCyzfvhpu4CwYe86wUuD.

2

Backend API (oracle + database)

Vercel serverless functions: /api/sleep (log sleep + oracle submit_sleep), /api/challenge (create/fetch challenges), /api/leaderboard, /api/treasury (real-time balance from Solana RPC). Neon Postgres as database. Backend signs oracle transactions with treasury key.

3

React Native mobile app

Expo + React Native with 3 tabs: Home (sleep dashboard, weekly chart, challenge status), Leaderboard (top sleepers with wallet addresses), Treasury (real-time SOL balance from devnet, explorer link). MWA for transaction signing via Phantom/Solflare.

4

Health Connect + sleep validation

Automatic sleep data import from Android Health Connect. Filtering invalid sessions (24h bug, short naps). Time window 6PM-2PM next day. Miss detection - days without entries shown as losses.

Describe what you want to improve - quote in 24h

Tell us what you need - automation, integration, AI agent or an app. You get a concrete quote for exactly what you want: what we'll do, what it costs and when it goes live.

Project process

2 days

Day 1-2

Architecture + Anchor program: PDA design, smart contract development and devnet deployment, instruction testing

1
2 days

Day 3-4

Backend API + database: REST endpoints, oracle signing, Neon Postgres schema, Solana RPC integration

2
2 days

Day 5-6

Mobile app: UI (3 tabs), MWA integration, Health Connect, manual instruction building with IDL discriminators

3
1 day

Day 7

Bug fixing: 24h sleep bug, wrong day labels, HC permission flow, treasury real-time balance, APK build + deploy

4

Project duration

1 week

Scope of work

Mobile App + Smart Contract (Anchor)

Technologies

Anchor 0.32 (Solana)
React Native (Expo)
TypeScript
Mobile Wallet Adapter
Health Connect (Android)
Neon Postgres
Vercel (API)
Solana devnet

Project gallery

Planning a similar project?

Book a free consultation to discuss your project.

Book a free consultation