Hazina means treasure in Swahili.
A Web3 data marketplace where sellers list valuable on-chain intelligence and buyers β including autonomous AI agents β purchase access using micropayments on Stellar. A Soroban smart contract enforces escrow on-chain. Claude AI synthesises every dataset into instant insights.
- What Problem Does Hazina Solve?
- Soroban Smart Contract
- How the App Works
- AI Research Agent
- Tech Stack
- Project Structure
- Getting Started
- Run with Docker
- Pages & Features
- API Reference
- Payment Flow Deep Dive
- Environment Variables
AI agents can't pay for data they need. When an autonomous agent requires paid on-chain intelligence, it hits a wall β rate limits, waiting for a human to set up a subscription, or going without. Meanwhile, data creators can't charge per-use because traditional payment rails ($0.30 minimum fees) make micropayments impossible.
Hazina fixes both sides:
- Agents autonomously discover and pay for data via x402 micropayments on Stellar β no human needed.
- Sellers earn USDC per query at fractions of a cent, enforced by a Soroban smart contract.
The Hazina escrow contract is written in Rust, compiled to WebAssembly, and deployed on the Stellar Soroban smart contract platform.
| Contract ID | CCPG2CSL6WDUA2IFUDHFN5SCJQUTFCLFKMTARALQ5RWGB2RGG345HEEH |
| Network | Stellar Testnet |
| Explorer | View on Stellar Expert |
| Admin | GA72WMKUB52OD2X437YOTJZXP3J7MV5G2RYC2JHFJJHWF6MBGQHVUMLO |
| Platform Fee | Default 5% (500 basis points), configurable per dataset |
| Source | contracts/hazina-escrow/src/lib.rs |
The contract is a trustless escrow β it holds a buyer's USDC payment and only releases it when the Hazina backend confirms data delivery. Neither the buyer nor the seller can cheat:
Buyer Contract Seller
β β β
βββlock(USDC)βββΊ β β
β β (funds held β
β β on-chain) β
β β β
β [Backend verifies β
β data was delivered] β
β β β
β βββrelease(95%)βββββΊ β
β βββplatform feeβββββΊ Admin
| Function | Who Calls It | What It Does |
|---|---|---|
initialize(admin, fee_bps) |
Deployer (once) | Sets the admin address and default platform fee (500 = 5%) |
set_default_fee(admin, fee_bps) |
Hazina backend (admin) | Updates the fallback fee used when no dataset override exists |
set_dataset_fee(admin, dataset_id, fee_bps) |
Hazina backend (admin) | Sets a custom platform fee for a specific dataset |
clear_dataset_fee(admin, dataset_id) |
Hazina backend (admin) | Removes a dataset-specific fee override |
set_whitelist_enforced(admin, enforced) |
Hazina backend (admin) | Toggles whitelist mode for participant addresses |
set_address_whitelisted(admin, address, whitelisted) |
Hazina backend (admin) | Marks an address as whitelist-approved |
set_address_blacklisted(admin, address, blacklisted) |
Hazina backend (admin) | Blocks or unblocks a malicious address |
lock(buyer, seller, token, amount, dataset_id) |
Buyer | Transfers USDC from buyer into the contract. Returns an escrow_id. |
release(admin, escrow_id) |
Hazina backend (admin) | Sends 95% to seller, 5% to admin. Fires a released event. |
refund(admin, escrow_id) |
Hazina backend (admin) | Returns full amount to buyer if something goes wrong. |
get_escrow(escrow_id) |
Anyone | Reads an escrow record (buyer, seller, amount, status). |
get_fee() |
Anyone | Returns the default platform fee in basis points. |
get_dataset_fee_config(dataset_id) |
Anyone | Returns the effective fee config for a dataset override. |
get_address_policy(address) |
Anyone | Returns whitelist and blacklist status for an address. |
- On-chain enforcement β the payment routing (95/5 split) is code, not promises.
- Trustless β buyers don't have to trust the Hazina server to route their money correctly.
- Auditable β every
lock,release, andrefundemits an on-chain event visible to anyone. - Native USDC β operates directly on Stellar's USDC, same asset as the x402 payments.
# Install Stellar CLI
brew install stellar-cli
# Build
cd contracts/hazina-escrow
stellar contract build
# Add your keypair
stellar keys add hazina-admin --secret-key
# Deploy to testnet
stellar contract deploy \
--wasm target/wasm32v1-none/release/hazina_escrow.wasm \
--source hazina-admin \
--network testnet
# Initialise (run once after deploy)
stellar contract invoke \
--id <CONTRACT_ID> \
--source hazina-admin \
--network testnet \
-- initialize \
--admin <YOUR_WALLET> \
--platform_fee_bps 500npm run contracts:check
npm run contracts:formalcontracts:checkrunscargo fmt --check,cargo clippy, the full Rust test suite, and a release wasm build.contracts:formalruns the invariant-oriented contract tests prefixed withformal_.
Seller β /sell page
β Name, description, price, Stellar wallet address, JSON data
β Click "Publish to Marketplace"
β Dataset live instantly, earnings tracked per query
Buyer β /marketplace
β Filter by type (whale wallets, DeFi yields, sentiment, risk scoresβ¦)
β Click "Buy Query" on any dataset
β Modal shows price, seller wallet, payment instructions
Browser Backend Stellar
β β β
β POST /api/query/:id β β
β ββββββββββββββββββββββββββΊ β β
β β β
β ββββββββββββββββββββββββββ β β
β 402 { address, amount, β β
β memo, expiresIn } β β
β β β
β [Buyer sends USDC] β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββΊβ
β β β
β POST /api/verify/:id β β
β { txHash } β β
β ββββββββββββββββββββββββββΊ β β
β β Horizon API check β
β β βββββββββββββββββββββββΊβ
β β βββββββββββββββββββββββ β
β β Payment confirmed β β
β β β
β β [Claude AI summary] β
β β [Auto-pay seller 95%] β
β β βββββββββββββββββββββββΊβ
β β β
β ββββββββββββββββββββββββββ β β
β 200 { data, AI summary, β β
β sellerTxHash } β β
Security checks on every payment:
- Transaction exists and is confirmed on Stellar
- Payment destination is the correct escrow wallet
- Amount is exactly right (within 0.001 USDC tolerance)
- Memo matches this specific query (prevents payment reuse)
- Transaction is less than 5 minutes old
- Transaction hash has never been used before (replay attack prevention)
Buyer receives:
β Full raw dataset (JSON, downloadable)
β Claude AI executive summary (3 key insights)
β Answer to their custom question
β On-chain proof of seller payment (sellerTxHash)
Every verified purchase:
β 95% β seller's Stellar wallet (on-chain, immediate)
β 5% β platform escrow wallet
β Stats updated (queriesServed, totalEarned)
β Transaction logged for /dashboard
The flagship feature. An autonomous agent that buys data from multiple sellers and synthesises a research report β with no human in the loop.
User pays 1 USDC to agent escrow wallet
β
βΌ
Agent verifies payment on Stellar (real tx)
β
βΌ
Agent autonomously pays 4 data sellers via x402:
βββ DeFi Yield Snapshot β 0.02 USDC
βββ Whale Wallet Movements β 0.05 USDC
βββ Wallet Risk Scores β 0.03 USDC
βββ Social Sentiment β 0.04 USDC
β
βΌ
Claude synthesises all 4 datasets into a research report:
βββ Top opportunity (protocol, APY, chain, risk level)
βββ Reasoning (cross-referencing all 4 data sources)
βββ 2 alternative opportunities
βββ Risk warnings
β
βΌ
Agent keeps 0.86 USDC profit
| Endpoint | Description |
|---|---|
GET /api/agent/info |
Agent wallet address, fee, seller list, profit model |
POST /api/agent/research |
Real mode β requires 1 USDC Stellar payment + txHash |
POST /api/agent/research/demo |
Demo mode β simulates payments, calls Claude for real |
curl -X POST http://localhost:3001/api/agent/research/demo \
-H "Content-Type: application/json" \
-d '{"query": "best low risk USDC yield with $500 budget"}'Returns a full JSON research report with top opportunity, reasoning, alternatives, and warnings.
| Layer | Technology | What It Does |
|---|---|---|
| Frontend | React 18 + Vite + TypeScript | Marketplace, sell, dashboard, agent UI |
| Styling | TailwindCSS | Afrofuturist dark gold theme |
| Backend | Node.js + Express + TypeScript | API server, payment verification, agent orchestration |
| Smart Contract | Rust + Soroban (WebAssembly) | On-chain escrow, trustless payment routing |
| Blockchain | Stellar Testnet + x402 protocol | Micropayments, USDC settlement |
| AI | Anthropic Claude (claude-sonnet-4-6) |
Data analysis + research synthesis |
| Storage | JSON file (data/datasets.json) |
Datasets and transaction history |
Hazina-Escrow/
β
βββ contracts/ β Soroban smart contracts (Rust)
β βββ hazina-escrow/
β βββ Cargo.toml β Rust package config
β βββ src/lib.rs β Escrow contract: lock/release/refund
β
βββ backend/ β Node.js API server (port 3001)
β βββ .env β API keys, wallet secrets, contract ID
β βββ src/
β βββ main.ts β Express setup, routes
β βββ common/
β β βββ storage.ts β Reads/writes data/datasets.json
β βββ datasets/
β β βββ datasets.router.ts β List, create, get datasets
β βββ payments/
β β βββ payments.router.ts β x402 flow + seller auto-payment
β β βββ stellar.service.ts β Stellar Horizon payment verification
β βββ agent/
β β βββ agent.router.ts β /api/agent/* endpoints
β β βββ agent.service.ts β Orchestrates: verify β buy β synthesise
β β βββ agent.wallet.ts β Signs & sends USDC from agent keypair
β βββ ai/
β βββ claude.service.ts β Dataset summaries for marketplace
β βββ research.service.ts β Full research report synthesis
β
βββ frontend/ β React app (port 5173)
β βββ src/
β βββ App.tsx β Routing
β βββ pages/
β β βββ LandingPage.tsx β Hero, stats, how-it-works
β β βββ MarketplacePage.tsx β Browse, filter, buy datasets
β β βββ SellPage.tsx β Upload data, set price, publish
β β βββ DashboardPage.tsx β Earnings & transaction history
β β βββ AgentPage.tsx β AI research agent UI
β βββ components/
β β βββ layout/Navbar.tsx β Navigation
β β βββ ui/
β β βββ DatasetCard.tsx β Dataset cards in marketplace
β β βββ QueryModal.tsx β Payment flow modal
β βββ lib/
β βββ api.ts β Typed API client (datasets + agent)
β βββ utils.ts β Formatting helpers
β
βββ data/
β βββ datasets.json β 6 seeded datasets + 42 transactions
β
βββ README.md
- Node.js 18+
- Anthropic API key β console.anthropic.com
- Rust +
stellar-cli(only needed to rebuild the contract)
npm run install:allEdit backend/.env:
PORT=3001
FRONTEND_URL=http://localhost:5173
# Required
ANTHROPIC_API_KEY=sk-ant-...
# Escrow wallet (receives buyer payments, forwards to sellers)
ESCROW_WALLET=GA72WMKUB52OD2X437YOTJZXP3J7MV5G2RYC2JHFJJHWF6MBGQHVUMLO
ESCROW_SECRET=your_escrow_wallet_secret_here
# Agent wallet (pays data sellers autonomously)
AGENT_WALLET_SECRET=your_agent_wallet_secret_here
AGENT_WALLET_PUBLIC=your_agent_wallet_public_key_here
# Soroban escrow contract (Stellar Testnet)
ESCROW_CONTRACT_ID=CCPG2CSL6WDUA2IFUDHFN5SCJQUTFCLFKMTARALQ5RWGB2RGG345HEEH
PLATFORM_FEE=0.05# Terminal 1 β Backend
cd backend && npm run start:dev
# Terminal 2 β Frontend
cd frontend && npm run dev- Backend: http://localhost:3001
- Frontend: http://localhost:5173
Every dataset has demo mode β in the buy modal, tick "Demo mode" to get a full Claude AI analysis without sending a real Stellar payment.
The AI Agent also has demo mode β go to /agent, type any query, click Run Agent.
- Docker Desktop (or Docker Engine + Compose plugin)
- A configured
backend/.envfile
docker compose up --build- Frontend (Vite HMR): http://localhost:5173
- Backend API: http://localhost:3001
- Backend uses
backend/.envviaenv_file data/datasets.jsonis bind-mounted to/app/data/datasets.jsonso data persists across container restarts
docker compose -f docker-compose.prod.yml up --build- Frontend is built and served by nginx on http://localhost
- nginx proxies
/api/*traffic to the backend container - Backend is compiled with
tscand run vianode dist/main.js
docker compose down
docker compose -f docker-compose.prod.yml down- Live animated stats (datasets, queries, USDC earned)
- How It Works walkthrough
- Featured datasets
- Links to marketplace and agent
- 6 seeded datasets (whale wallets, DeFi yields, risk scores, sentiment, NFT, arbitrage)
- Filter by type, sort by price/popularity, search
- Click any card β payment modal with demo mode checkbox
- Form: name, description, type, price, Stellar wallet, JSON data
- Live preview card
- Earnings calculator (10 / 100 / 1000 query projections)
- Instant publish to marketplace
- Natural language query input
- Example queries to click
- Returns: top opportunity, reasoning, 2 alternatives, warnings, full analysis
- Shows payment trail (4 seller payments + agent profit)
- Real-time transaction list
- Per-dataset earnings
- Queries served counter
| Method | Endpoint | Description |
|---|---|---|
GET |
/health |
Server health check |
GET |
/api/datasets |
All datasets (metadata only) |
GET |
/api/datasets/stats |
Platform totals |
GET |
/api/datasets/:id |
Single dataset metadata |
POST |
/api/datasets |
Create new listing |
GET |
/api/datasets/:id/transactions |
Transaction history |
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/query/:id |
Initiate query β 402 with payment instructions |
POST |
/api/verify/:id |
Submit txHash β verify on Stellar β release data + pay seller |
POST |
/api/verify/:id/demo |
Demo mode β skip payment, get AI analysis |
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/agent/info |
Agent wallet, fee, sellers, profit model |
POST |
/api/agent/research |
Real mode β requires txHash of 1 USDC payment |
POST |
/api/agent/research/demo |
Demo mode β simulated payments, real Claude synthesis |
HTTP's 402 Payment Required status code β defined in 1991, never widely used until now. Hazina implements it as a machine-readable payment protocol: any client (browser or AI agent) receives structured payment instructions and can act on them without human intervention.
- 3β5 second finality β no waiting for confirmations
- $0.00001 fees β viable for $0.02 micropayments
- Native USDC β stable, no price volatility
- Soroban β WebAssembly smart contracts in any language
1. Buyer sends 0.05 USDC to escrow wallet on Stellar (via Freighter)
2. Buyer submits txHash to POST /api/verify/:id
3. Backend checks Horizon API: amount β destination β memo β expiry β
4. Claude generates AI summary of the dataset
5. Backend sends 0.0475 USDC β seller wallet (on-chain, new tx)
6. Response includes: data + AI summary + sellerTxHash
1. User sends 1 USDC to agent escrow wallet
2. POST /api/agent/research { query, txHash }
3. Agent verifies incoming payment on Stellar
4. Agent signs 4 outgoing Stellar transactions (one per seller)
5. Claude synthesises all 4 datasets into research report
6. Response: report + payment trail (4 txHashes) + agent profit
| ID | Dataset | Price | Seller Wallet |
|---|---|---|---|
| ds-001 | Top 100 Whale Wallet Movements | $0.05 | GB37MSLK... |
| ds-002 | DEX Arbitrage Signals β Last 24hrs | $0.10 | GA62DGF2... |
| ds-003 | DeFi Yield Snapshot β 20+ Protocols | $0.02 | GD4GDOPE... |
| ds-004 | Wallet Risk Scores β Top 500 DeFi Wallets | $0.03 | GBMVCBYW... |
| ds-005 | NFT Floor Price Movements β Last 7 Days | $0.02 | GCDDN2PN... |
| ds-006 | Crypto Social Sentiment Scores | $0.04 | GC42G7GQ... |
All seller wallets are funded Stellar testnet accounts with USDC trustlines, ready to receive payments.
| Variable | Required | Description |
|---|---|---|
ANTHROPIC_API_KEY |
Yes | Claude API key β console.anthropic.com |
ESCROW_WALLET |
Yes | Stellar address that receives buyer payments |
AGENT_WALLET_SECRET |
Yes | Agent's Stellar secret key (signs outgoing seller payments) |
AGENT_WALLET_PUBLIC |
No | Agent's Stellar public key (display only) |
ESCROW_CONTRACT_ID |
No | Soroban contract address (for on-chain escrow integration) |
PLATFORM_FEE |
No | Platform cut as decimal (default: 0.05) |
PORT |
No | API port (default: 3001) |
FRONTEND_URL |
No | CORS origin (default: http://localhost:5173) |
Afrofuturist aesthetic β luxury dark theme inspired by the Kente cloth geometric patterns of West Africa. The name Hazina (treasure in Swahili) reflects the untapped value in on-chain intelligence.
| Token | Value |
|---|---|
| Background | #0A0A0F (void black) |
| Accent | #C9A84C (gold) |
| Heading font | Playfair Display |
| Body font | DM Sans |
| Cards | Glass morphism with gold borders |
| Patterns | Kente-inspired SVG geometry |