The SportsBetting
contract allows users to place bets on sports events, calculate odds, and settle events. This guide will walk you through the process of interacting with the contract using Etherscan.
- Access to Etherscan with the contract deployed.
- A web3-enabled browser or an Ethereum wallet like MetaMask.
- Some ETH in your wallet for transactions.
To create a new betting event:
- Go to the Etherscan page of the
SportsBetting
contract. - Connect your wallet by clicking on the “Connect to Web3” button.
- Navigate to the “Write Contract” tab.
- Find the
addEvent
function in the list. - Enter the name of the event in the
eventName
field.- Example:
"Soccer Match 1"
- Example:
- Confirm and sign the transaction in your wallet.
To place a bet on an event:
- Ensure you are still connected to your wallet.
- Under the “Write Contract” tab, locate the
placeBet
function. - Enter the
eventId
of the event you want to bet on. This is typically the index of the event.- Example:
0
for the first event
- Example:
- Enter the
selectedOutcome
.- Example:
0
for Team X,1
for Team Y,2
for a draw
- Example:
- Specify the bet amount in the transaction value field (ensure this is in Wei).
- Example: To bet 0.01 ETH, enter
10000000000000000
- Example: To bet 0.01 ETH, enter
- Confirm and sign the transaction.
To settle an event and determine the winning outcome:
- Find the
settleEvent
function under the “Write Contract” tab. - Enter the
eventId
of the event you want to settle.- Example:
0
for the first event
- Example:
- Enter the
winningOutcome
.- Example:
0
for Team X,1
for Team Y,2
for a draw
- Example:
- Confirm and sign the transaction.
Odds are calculated automatically when a bet is placed. To view the odds:
- Navigate to the “Read Contract” tab.
- Find the
getBetData
function. - Enter the
eventId
and the bettor’s address.- Example:
eventId
-0
,bettor's address
-0x123...
- Example:
- The function will return bet details, including the calculated odds.
- Transactions require ETH for gas fees.
- Ensure you are interacting with the correct contract and network.
- The contract owner is the only one who can add events and settle them.