Skip to main content

getBetDetails

The getBetDetails method is a straightforward way to fetch detailed information about a specific bet. By providing the unique betId, developers can retrieve all the essential details related to the bet, such as the bettor's address, amount staked, payout information, odds, status, and more.
This method is particularly useful for applications where users need to view or manage individual bets, such as showing a bet's history, verifying its status, or analyzing the bet's outcomes. It also handles errors gracefully, ensuring a seamless experience even if the bet information cannot be retrieved.

Usage

import kohin from "./kohinInstance";

const betDetailsParams = {
betId: "0x471dac1052248602fdf05377ef99b5b7b3a769a", // Unique identifier of the bet
};

const betDetails = await kohin.getBetDetails(betDetailsParams);
console.log("Bet Details:", betDetails);

Parameters

ParameterTypeDescription
betIdstringThe unique identifier for the bet whose details are to be fetched.

Return Value

Returns a Promise resolving to an object with the following structure:

{
success: boolean; // Indicates whether the call was successful
data?: { // Bet details object (present if successful)
bettor: string;
amount: string;
odds: string;
payout: any;
result: any;
status: string;
type: string;
settledOdds: any;
betId: string;
potentialPayout: string;
createdBlockTimestamp: string;
_lostSubBetsCount: number;
_subBetsCount: number;
_updatedAt: string;
_conditions: Condition[];
selections: Selection[];
_games: Game[];
_conditionIds: string[];
};
error?: string; // Error message if the call fails
}

interface Condition {
conditionId: string;
coreAddress: string;
game: Game;
}

interface Game {
league: League;
title: string;
startsAt: string;
}

interface League {
name: string;
}

interface Selection {
_outcomeId: string;
odds: string;
}

Error Handling

The response contains an error field when the API call fails. You can use this to provide meaningful feedback to the user:

try {
const betDetails = await kohin.getBetDetails({
betId: "0x471dac1052248602fdf05377ef99b5b7b3a769a",
});
if (!betDetails.success) {
console.error("Error:", betDetails.error);
// Display the error message to the user
toastify(betDetails.error, "error");
} else {
console.log("Bet Details:", betDetails.data);
}
} catch (error) {
console.error("Unexpected error:", error.message);
// Display a fallback error message
toastify("Failed to fetch bet details. Please try again.", "error");
}

Example Response

Success Response:

{
"success": true,
"code": 200,
"data": {
"bettor": "0x34ca07db523c2ea867bd1d1dccc46de3eb6daae3",
"amount": "1",
"odds": "2.021694448858",
"payout": null,
"result": null,
"status": "Accepted",
"type": "Express",
"settledOdds": null,
"betId": "405",
"potentialPayout": "2.021694",
"createdBlockTimestamp": "1743761974",
"_lostSubBetsCount": 0,
"_subBetsCount": 2,
"_updatedAt": "1743761974",
"_conditions": [
{
"conditionId": "100610060000000000642348110000000000000928988958",
"coreAddress": "0x87ebffe283be8ded47c3c87451d1b89c8a2c441a",
"game": {
"league": {
"name": "Bundesliga"
},
"title": "FC Augsburg – FC Bayern Munchen",
"startsAt": "1743791400"
}
},
{
"conditionId": "100610060000000000645669270000000000000928989600",
"coreAddress": "0x87ebffe283be8ded47c3c87451d1b89c8a2c441a",
"game": {
"league": {
"name": "Bundesliga"
},
"title": "FSV Mainz 05 – Holstein Kiel",
"startsAt": "1743859800"
}
}
],
"selections": [
{
"_outcomeId": "31",
"odds": "1.387326654924"
},
{
"_outcomeId": "29",
"odds": "1.45725914058"
}
],
"_games": [
{
"title": "FC Augsburg – FC Bayern Munchen",
"league": {
"name": "Bundesliga"
},
"startsAt": "1743791400"
},
{
"title": "FSV Mainz 05 – Holstein Kiel",
"league": {
"name": "Bundesliga"
},
"startsAt": "1743859800"
}
],
"_conditionIds": [
"100610060000000000642348110000000000000928988958",
"100610060000000000645669270000000000000928989600"
]
},
"message": "OK",
"detailMessage": null,
"error": ""
}

Error Response:

{
"success": false,
"error": "Invalid bet ID"
}