Skip to content

Create Wallet functions to interact with Blockchain contract #24

@SumanthPal

Description

@SumanthPal

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):

  1. useBettingContract.ts

    • Core contract interactions
    • Read/write functions wrapped
    • Contract address & ABI configuration
    • Transaction state management
  2. 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)
  3. 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:

  1. 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
  2. TournamentCard.tsx

    • Display tournament ID, status, total pool
    • List all agents with current odds
    • Pool distribution visualization
    • Betting active/closed indicator
  3. ClaimWinnings.tsx

    • Show if user has winning bets
    • Display payout amount (from calculatePayout)
    • Claim button (disabled if already claimed)
    • Handle refunds for cancelled tournaments
  4. 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.

Metadata

Metadata

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions