Ok good job ygs with designing the wallet! Now, we gotta add some functionality by having the wallet interact with the escrow. We can achieve this with creating hooks + some simple components to interact with it.
But first you have to understand how the contract works:
- Look at the contract code above for reference
- The contract is deployed on Base Sepolia
- It uses parimutuel betting (pool-based, not fixed odds)
- Platform takes 5% fee, minimum bet is 0.001 ETH
- Tournaments go through states: Active → Closed → Settled
- Users can bet on agents (1 to N), claim winnings after settlement
What we need to build:
Hooks (using wagmi + viem):
-
useBettingContract.ts
- Core contract interactions
- Read/write functions wrapped
- Contract address & ABI configuration
- Transaction state management
-
useTournament.ts
- Fetch tournament data (isActive, isSettled, totalPool, agentCount, winningAgentId)
- Get agent pools and odds for all agents
- Real-time updates using wagmi's watch functions
- Calculate odds display (convert BP to readable format)
-
useUserBets.ts
- Get user's bets for a tournament (all agents)
- Check if user has claimed
- Calculate potential payout
- Track user's total exposure
Components:
-
PlaceBetForm.tsx
- Select agent dropdown/buttons
- ETH input with min validation (0.001 ETH)
- Show current odds for selected agent
- Transaction button with loading states
- Success/error toast notifications
-
TournamentCard.tsx
- Display tournament ID, status, total pool
- List all agents with current odds
- Pool distribution visualization
- Betting active/closed indicator
-
ClaimWinnings.tsx
- Show if user has winning bets
- Display payout amount (from calculatePayout)
- Claim button (disabled if already claimed)
- Handle refunds for cancelled tournaments
-
UserBetsPanel.tsx
- List user's bets per agent
- Show total amount bet
- Display potential winnings
- Claim status
Additional utilities:
- Format wei to ETH helper
- Calculate odds display (BP to decimal/fractional)
- Tournament status helpers
- Error message mapping
Look at the discord for more information in #contracts
ABI: Reference #23
Use wagmi's useContractRead, useContractWrite, useWaitForTransaction patterns. Handle loading, error, and success states properly. Make hooks reusable and composable.
Ok good job ygs with designing the wallet! Now, we gotta add some functionality by having the wallet interact with the escrow. We can achieve this with creating hooks + some simple components to interact with it.
But first you have to understand how the contract works:
What we need to build:
Hooks (using wagmi + viem):
useBettingContract.tsuseTournament.tsuseUserBets.tsComponents:
PlaceBetForm.tsxTournamentCard.tsxClaimWinnings.tsxUserBetsPanel.tsxAdditional utilities:
Look at the discord for more information in #contracts
ABI: Reference #23
Use wagmi's
useContractRead,useContractWrite,useWaitForTransactionpatterns. Handle loading, error, and success states properly. Make hooks reusable and composable.