A decentralized prediction market platform built on Ethereum that allows users to bet on binary outcomes using ERC20 tokens. Built with Next.js, TypeScript, Thirdweb, and Solidity.
- Create Markets: Set up prediction markets with two possible outcomes
- Buy Shares: Purchase shares representing your belief in an outcome
- Automated Market Making: Dynamic share pricing based on total holdings
- Claim Winnings: Winners receive their stake plus a proportional share of losing bets
- Multi-tab Interface: View active, pending, and resolved markets
- Web3 Integration: Connect wallet with account abstraction support
- Token Faucet: Claim test tokens to participate in markets
- Next.js 15: React framework with App Router
- TypeScript: Type-safe development
- Thirdweb SDK: Web3 integration and wallet management
- shadcn/ui: Beautiful UI components built on Radix UI
- Tailwind CSS: Utility-first styling
- Solidity: Smart contract development
- Foundry: Testing and deployment framework
- OpenZeppelin: Secure contract standards
- Sepolia Testnet: Ethereum test network
- ERC20 Token: Custom prediction token (PMT)
- Node.js 18+ and npm/yarn
- MetaMask or compatible Web3 wallet
- Sepolia testnet ETH (for gas fees)
git clone https://github.com/zntb/nextjs-web3-simple-prediction-market.git
cd nextjs-web3-simple-prediction-marketnpm installCreate a .env.local file in the root directory:
NEXT_PUBLIC_THIRDWEB_CLIENT_ID=your_thirdweb_client_id
# Backend API variables
RPC_URL=https://sepolia.infura.io/v3/your_infura_key
PRIVATE_KEY=your_wallet_private_key
TOKEN_ADDRESS=0x1Cc10F13Ea489ea3184D397196c892B148e0478CGet your Thirdweb Client ID:
- Visit Thirdweb Dashboard
- Create a new project
- Copy your Client ID
npm run devOpen http://localhost:3000 to view the application.
The contracts are located in the pmcontract directory.
cd pmcontract
forge build
forge test
npx thirdweb deploy- Prediction Market:
0x565fBDEBa409Cdf03EeC311eB96be3FDBF3e67D8 - Prediction Token (PMT):
0x1Cc10F13Ea489ea3184D397196c892B148e0478C
- Connect Wallet: Click "Sign In" to connect via in-app wallet
- Claim Tokens: Get free PMT tokens from the faucet
- Browse Markets: View active prediction markets
- Buy Shares: Select an outcome and purchase shares
- Claim Winnings: After resolution, claim your rewards
Markets can be created by calling the createMarket function on the smart contract:
createMarket(
"Will ETH reach $5000 by 2025?",
"Yes",
"No",
7 days
)โโโ src/
โ โโโ app/
โ โ โโโ api/claimToken/ # Token faucet API
โ โ โโโ layout.tsx
โ โ โโโ page.tsx
โ โโโ components/
โ โ โโโ ui/ # shadcn/ui components
โ โ โโโ enhanced-prediction-market-dashboard.tsx
โ โ โโโ marketCard.tsx
โ โ โโโ market-buy-interface.tsx
โ โ โโโ market-resolved.tsx
โ โ โโโ navbar.tsx
โ โโโ constants/
โ โ โโโ contract.ts # Contract addresses
โ โ โโโ tokenAbi.json
โ โโโ lib/utils.ts
โโโ pmcontract/
โ โโโ src/
โ โโโ SimplePredictionMarket.sol
โโโ public/
Key functions:
createMarket(): Create a new prediction marketbuyShares(): Purchase shares for an outcomeresolveMarket(): Set the winning outcome (owner only)claimWinnings(): Claim rewards for winning betsgetMarketInfo(): Retrieve market detailsgetSharesBalance(): Check user's share balance
Winners receive:
winnings = userShares + (userShares ร losingShares / winningShares)
This ensures:
- You get your original stake back
- Plus a proportional share of all losing bets
# Frontend tests
npm run test
# Smart contract tests
cd pmcontract
forge testnpm run build
# Deploy to Vercel or your preferred platformcd pmcontract
npx thirdweb deployContributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Live Demo: [Add your deployment URL]
- Documentation: [Add documentation link]
- Discord: [Add community link]
- Thirdweb for Web3 infrastructure
- shadcn/ui for UI components
- OpenZeppelin for secure contracts
Your Name - @yourusername
Project Link: https://github.com/zntb/nextjs-web3-simple-prediction-market
