Bitcoin Prediction Markets powered by Charms Protocol โก
A decentralized prediction market platform built on Bitcoin Testnet4, powered by the Charms protocol. Trade on future outcomes using Bitcoin-native smart contracts with zero-knowledge proofs.
Built for: The BOS Hackathon - Building Bitcoin Smart Contracts with the BitcoinOS Stack at Encode Club
| Repo | Description |
|---|---|
| echo-markets | Charms smart contracts (Rust) |
| echo-markets-frontend | Web application (this repo) |
- Create Markets โ Launch prediction markets with custom questions, deadlines, and fees
- Mint Shares โ Deposit BTC to receive YES + NO tokens
- Burn Shares โ Burn equal YES + NO to recover BTC (before resolution)
- P2P Trading โ Swap YES tokens for NO (and vice versa)
- Portfolio Tracking โ Real-time P&L, position values, and transaction history
- Wallet Integration โ Full BIP39/BIP86 Taproot wallet with Schnorr signatures
- Zero-Knowledge Proofs โ Private, verifiable transactions via Charms
- Bitcoin Native โ Built on Bitcoin Testnet4, no sidechains
- Taproot Wallets โ BIP86 derivation with Schnorr signatures
- Transaction Polling โ Automatic confirmation tracking
- Modern Stack โ Next.js 15, React 19, TypeScript, Tailwind CSS v4
- Node.js 20+ and npm
- Bitcoin Testnet4 coins (mempool faucet)
- Charms CLI (for contract compilation)
# Clone the repository
git clone https://github.com/EchoMarkets/echo-markets-frontend.git
cd echo-markets-frontend
# Install dependencies
npm install
# Set up environment variables
cp .env.example .env.localCreate a .env.local file:
# Charms Prover API
CHARMS_PROVER_URL=https://v8.charms.dev/spells/prove
# Mempool API (testnet4)
MEMPOOL_API=https://mempool.space/testnet4/api
# Contract Verification Key
# Generate with: charms app vk --wasm ./contracts/echo-markets.wasm
APP_VK=your_verification_key_here
# Path to compiled contract
APP_WASM_PATH=./contracts/echo-markets.wasmnpm run dev
# Open http://localhost:3000npm run build
npm startecho-markets-frontend/
โโโ app/
โ โโโ api/charms/ # Charms API routes
โ โ โโโ broadcast/ # Transaction broadcasting
โ โ โโโ cast/ # Prove + sign + broadcast
โ โ โโโ prove/ # ZK proof generation
โ โโโ create/ # 4-step market creation wizard
โ โโโ market/[id]/ # Market detail + trading
โ โโโ portfolio/ # Positions, P&L, transactions
โ โโโ wallet/ # Wallet setup & management
โโโ components/
โ โโโ layout/ # Header, navigation
โ โโโ market/ # MarketCard
โ โโโ trading/ # TradingPanel, SharesInput, PriceImpact
โ โโโ wallet/ # WalletSetup, WalletDisplay, FundingInstructions
โ โโโ ui/ # Button, Toaster
โโโ lib/
โ โโโ bitcoin.ts # Taproot signing, UTXOs, broadcasting
โ โโโ charms.ts # SpellBuilder (create, mint, trade, redeem)
โ โโโ charmsApi.ts # Prover API client
โ โโโ store.ts # Zustand stores (wallet, markets, portfolio)
โ โโโ useCharms.ts # React hook for all Charms operations
โ โโโ WalletService.ts # BIP39/BIP86 wallet management
โ โโโ utils.ts # Formatting, calculations
โโโ contracts/
โ โโโ echo-markets.wasm # Compiled Charms contract
โโโ types/
โโโ index.ts # TypeScript definitions
| Category | Technologies |
|---|---|
| Frontend | Next.js 15, React 19, TypeScript, Tailwind CSS v4, Framer Motion |
| State | Zustand with persist middleware |
| Bitcoin | @scure/btc-signer, @scure/bip32, @scure/bip39 |
| Crypto | @noble/curves (Schnorr), @noble/hashes (SHA256) |
| Protocol | Charms |
| API | Mempool.space API |
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ User Action โ โโโถ โ SpellBuilder โ โโโถ โ /api/charms/castโ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโฌโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Broadcast โ โโโ โ User Signs โ โโโ โ Charms Prover โ
โ to Bitcoin โ โ (Schnorr) โ โ [commit, spell] โ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
- Create โ Deploy market with question hash, deadlines, fees
- Mint โ Users deposit BTC โ receive equal YES + NO tokens
- Burn โ Users burn equal YES + NO โ recover BTC (before resolution)
- Trade โ P2P swaps between YES and NO holders
- Resolve โ Creator resolves with outcome (YES/NO/Invalid)
- Redeem โ Winners burn tokens โ receive 1 sat per token
- Claim Fees (future) โ Creator withdraws accumulated trading fees
- Cancel (future) โ Creator cancels unresolved market, users redeem at cost
| Spell | Description | Status |
|---|---|---|
Create |
Deploy new market NFT | โ Implemented |
Mint |
Deposit BTC, mint YES+NO tokens | โ Implemented |
Burn |
Burn equal YES+NO to recover BTC (before resolution) | โ SpellBuilder only |
Trade |
P2P swap (Charms token conservation) | โ Implemented |
Resolve |
Set market outcome | โ SpellBuilder only |
Redeem |
Burn winning tokens for BTC (after resolution) | โ Implemented |
ClaimFees |
Creator withdraws accumulated fees | ๐ฎ Future |
Cancel |
Creator cancels market, refunds holders | ๐ฎ Future |
Central hook for all Charms operations:
const { createMarket, mintShares, trade, redeemShares, isLoading } =
useCharms();
// Create market
const marketId = await createMarket({
question: "Will BTC reach $150k by 2025?",
tradingDeadline: 1735689600,
resolutionDeadline: 1735776000,
feeBps: 100,
minBet: 10000,
maxSupply: 1000000000,
});
// Mint shares
await mintShares({ marketId, amount: 50000 });
// P2P trade
await trade({
marketId,
sellOutcome: "Yes",
sellAmount: 1000,
sellUtxoId: "abc:0",
buyUtxoId: "def:1",
counterpartyAddress: "tb1p...",
});// Composable wallet UI
{
!wallet ? (
<WalletSetup /> // Create or import wallet
) : (
<>
<WalletDisplay /> // Address, balance, seed phrase
<FundingInstructions /> // Faucet links, auto-polling
</>
);
}<TradingPanel
market={market}
onTrade={handleTrade} // Calls useCharms.mintShares()
/>| Feature | Status |
|---|---|
| Wallet (BIP39/BIP86 Taproot) | โ |
| Market creation UI + on-chain | โ |
| Trading UI + on-chain minting | โ |
| P2P trade function | โ |
| Portfolio with real positions | โ |
| Transaction history | โ |
| Confirmation polling | โ |
| Charms spells (create, mint, burn, trade, resolve, redeem) | โ |
| API routes (prove, cast, broadcast) | โ |
- Retry logic for failed broadcasts
- Dynamic fee estimation
- Market resolution UI
- Burn shares UI
- Fee claiming UI for market creators
- Cancel market functionality
- Order book for P2P matching
- On-chain market indexing
- Testnet Only โ This is a testnet prediction market
- No Order Book โ P2P trades require knowing counterparty's UTXO
- Single Address โ Uses primary address only (24-address system exists but unused)
- Hardcoded Fees โ Uses 2 sat/vB, no dynamic estimation
| Aspect | Implementation |
|---|---|
| Key Storage | Client-side only, never sent to servers |
| Mnemonic | Standard BIP39 12-word phrase |
| Signing | Schnorr signatures (BIP340) |
| Addresses | Taproot P2TR (BIP86) |
- Push to GitHub
- Import in Vercel
- Add environment variables
- Deploy
Set in your deployment platform:
CHARMS_PROVER_URLMEMPOOL_APIAPP_VKAPP_WASM_PATH
| Resource | URL |
|---|---|
| Testnet Faucet | https://mempool.space/testnet4/faucet |
| Block Explorer | https://mempool.space/testnet4 |
| Charms Protocol | https://charms.dev |
- Charms Protocol โ Bitcoin smart contracts with ZK proofs
- BitcoinOS โ Bitcoin application layer
- Encode Club โ a global developer education community focused on Web3 and AI
MIT โ Built for the BitcoinOS x Encode Club Hackathon
Built with โก for Bitcoin