Menu

Explorer & Settings

Tempo Explorer Submit Project
Back to all projects

nba-bets

by Ujjwal-N · Updated 3 months ago

Real-time NBA micro-betting with on-chain USDC settlement via Tempo and MPP (Machine Payments Protocol)

Open source alternative to:

In the AI payments ecosystem

nba-bets is an early-stage Python project in the AI payments / x402 ecosystem. It currently has 0 GitHub stars and 0 forks.

README.md View on GitHub →

NBA Live Bets

Real-time micro-betting on NBA plays, settled on-chain via Tempo and MPP (Machine Payments Protocol).

Watch a real NBA game and place Yes/No bets on what happens next — "Does Steph Curry score first?", "Next score a 3-pointer?", "LeBron with a dunk?" — with bets resolving in seconds and USDC payouts on-chain.

How it works

  1. A YouTube video of an NBA game plays alongside real play-by-play data (synced via timestamps from the NBA API)
  2. The server generates bets tied to upcoming plays with odds-based payouts
  3. Players place bets via the browser UI (virtual) or via MPP (real USDC)
  4. When the play happens, the bet resolves and winners get paid

MPP integration

The POST /api/bet endpoint is an MPP-compatible service:

  • First request returns 402 Payment Required with an MPP challenge
  • Client pays USDC on the Tempo blockchain
  • Retry with payment proof registers the bet
  • Winners are paid out via tempo wallet transfer
tempo request -t -X POST \
  --json '{"bet_id":"b1","pick":"Yes","player":"you"}' \
  http://localhost:8000/api/bet

Setup

Prerequisites

  • Python 3.10+
  • uv
  • Tempo CLI (curl -fsSL https://tempo.xyz/install | bash)

Install

git clone <this-repo>
cd nba-bets
uv venv && uv pip install -r requirements.txt

Configure

cp .env.example .env
# Edit .env with your Tempo wallet address and a secret key

Get your wallet address:

tempo wallet login
tempo wallet -t whoami  # copy the wallet address

Run

uvicorn server:app --reload
# Open http://localhost:8000

Test

HOUSE_WALLET=0x... MPP_SECRET_KEY=test pytest

Architecture

index.html          Browser UI: YouTube player + bet cards + PBP feed
    |
    |--- WebSocket /ws/{name}    Game feed, bet prompts, results
    |--- POST /api/bet           MPP-protected bet placement (402 flow)
    v
server.py           FastAPI backend: game engine, bet lifecycle, MPP, Tempo
    |
    |--- betting.py              Core bet math (tested independently)
    |--- game_data.json          Real PBP data from NBA CDN
    |--- tempo wallet transfer   On-chain USDC payouts to winners

Game data

Uses real play-by-play from Lakers @ Warriors, Christmas Day 2024 (LAL 115 - GSW 113). PBP data from cdn.nba.com, video from YouTube. 25 pre-seeded bets covering Q1.

Audit log

Every bet open, pick, resolution, and Tempo transfer is logged:

GET /api/audit
All MPP projects →