### Install Dependencies for Example App
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/sdk/installation/page.mdx
Install the necessary Node.js dependencies after cloning the example application repository. This command should be run from the root of the cloned repository.
```bash
npm install
```
--------------------------------
### Install Azuro Template and Dependencies
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/get-started/page.mdx
Clone the Azuro example app repository, navigate into the project directory, and install all necessary project dependencies using npm.
```bash
git clone https://github.com/Azuro-protocol/example-app.git
cd example-app
npm install
```
--------------------------------
### Clone Azuro SDK Example App
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/sdk/installation/page.mdx
Clone the repository to use the sample dApp as a starting point for your project. This is the first step for building on top of the sample dApp.
```bash
git clone https://github.com/Azuro-protocol/example-app
```
--------------------------------
### Install Dependencies
Source: https://github.com/azuro-protocol/gem-docs/blob/main/README.md
Run this command in the project root to install all necessary Node.js dependencies.
```bash
npm i
```
--------------------------------
### Start Development Server
Source: https://github.com/azuro-protocol/gem-docs/blob/main/README.md
Execute this command to launch the local development server.
```bash
npm run dev
```
--------------------------------
### Install Azuro SDK in Your Project
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/sdk/installation/page.mdx
Install the Azuro SDK package using npm. This command should be run in your project's root directory.
```bash
npm install @azuro-org/sdk
```
--------------------------------
### Pagination Example
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/sdk/data-hooks/useSearchGames/page.mdx
Example demonstrating how to implement pagination with the useSearchGames hook by controlling the `page` and `perPage` props.
```APIDOC
## Pagination Example
```ts
import { useSearchGames } from '@azuro-org/sdk'
import { useState } from 'react'
const [currentPage, setCurrentPage] = useState(1)
const { data, isFetching } = useSearchGames({
input: 'Manchester',
page: currentPage,
perPage: 20
})
```
```
--------------------------------
### Install Peer Dependencies
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/toolkit/page.mdx
Install the required peer dependencies for the toolkit.
```bash
npm install @azuro-org/dictionaries@^3.0.27 graphql-tag@^2.12.6 @wagmi/core@^2.17.2 viem@^2.30.4
```
--------------------------------
### Example Usage: Fetching Games
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/APIs/graph/use/page.mdx
JavaScript examples demonstrating how to use the `GAMES_QUERY` to fetch prematch or live games. Ensure you have a GraphQL client configured.
```javascript
// Fetch prematch games
const prematchGames = await client.query({
query: GAMES_QUERY,
variables: {
where: {
state: 'Prematch',
activeConditionsCount_gt: 0
},
first: 20
}
});
// Fetch live games
const liveGames = await client.query({
query: GAMES_QUERY,
variables: {
where: {
state: 'Live',
activeConditionsCount_gt: 0
},
first: 20
}
});
```
--------------------------------
### Usage Example: Game Markets List (Option A)
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/sdk/watch-hooks/useConditionsState/page.mdx
Example of usage for game markets list, passing the full conditions array to get `hidden` state without an extra fetch.
```APIDOC
## Usage Example: Game Markets List (Option A)
Pass the full conditions array to get `hidden` state without an extra fetch.
```tsx
import { useConditionsState } from '@azuro-org/sdk'
// conditions: ConditionDetailedData[] from useConditions
const { data: states, conditionsMap } = useConditionsState({ conditions })
// hide conditions that are still hidden (temporarily stopped by provider)
const visibleConditions = conditions.filter(({ conditionId }) => !conditionsMap[conditionId]?.hidden)
```
```
--------------------------------
### Install Social AA Connector
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/guides/social-login/page.mdx
Install the SDK package for social account abstraction connector.
```bash
npm install @azuro-org/sdk-social-aa-connector
```
--------------------------------
### Install Required Packages
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/guides/deploying-azuro-subgraph/page.mdx
Install all necessary project dependencies using npm ci for a clean installation.
```bash
npm ci
```
--------------------------------
### Client Setup
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/APIs/graph/use/page.mdx
Instructions for setting up GraphQL clients for both the client subgraph and the data-feed subgraph using Apollo Client.
```APIDOC
## Client Setup
To use The Graph API in your application, you'll need to set up a GraphQL client. Here's an example using Apollo Client:
```javascript
import { ApolloClient, InMemoryCache, HttpLink } from '@apollo/client';
// Client subgraph client
const clientSubgraphClient = new ApolloClient({
link: new HttpLink({
uri: 'https://thegraph.onchainfeed.org/subgraphs/name/azuro-protocol/azuro-api-polygon-v3',
}),
cache: new InMemoryCache(),
});
// Data-feed subgraph client
const dataFeedSubgraphClient = new ApolloClient({
link: new HttpLink({
uri: 'https://thegraph-1.onchainfeed.org/subgraphs/name/azuro-protocol/azuro-data-feed-polygon',
}),
cache: new InMemoryCache(),
});
```
```
--------------------------------
### Install Required Peer Dependencies for Azuro SDK
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/sdk/installation/page.mdx
Install the essential peer dependencies required by the Azuro SDK. Ensure these versions are compatible with your project.
```bash
npm install @azuro-org/dictionaries@^3.0.27 graphql@^16.11.0 viem@^2.30.4 wagmi@^2.15.4
```
--------------------------------
### API Authorization Example
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/guides/freebets/third-party/page.mdx
Demonstrates how to authenticate API requests using an API token in the 'x-bonus-api-token' header. Obtain your token by contacting the support team.
```bash
curl -X 'POST' \
'https://api.onchainfeed.org/api/v1/public/bonus/external/offer/freebet/create' \
-H 'accept: application/json' \
-H 'x-bonus-api-token: api-token' \
-H 'Content-Type: application/json'
```
--------------------------------
### Install graph-cli
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/guides/deploying-azuro-subgraph/page.mdx
Install the Graph CLI globally using npm. This command is required before proceeding with subgraph deployment.
```bash
npm install -g @graphprotocol/graph-cli
```
--------------------------------
### Setup AzuroSDKProvider with Wagmi and QueryClient
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/sdk/providers/sdk/page.mdx
Wrap your application with AzuroSDKProvider, ensuring it's nested within WagmiProvider and QueryClientProvider. Provide the initialChainId for the SDK.
```tsx
import { AzuroSDKProvider } from '@azuro-org/sdk'
import { WagmiProvider, createConfig } from 'wagmi'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { polygonAmoy } from 'viem/chains'
const wagmiConfig = createConfig(config)
const queryClient = new QueryClient()
function Providers(props: { children: React.ReactNode }) {
const { children } = props
return (
{children}
)
}
```
--------------------------------
### Install SDK v7 and Toolkit v6 Dependencies
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/sdk/migration-v7/page.mdx
Commands to update the '@azuro-org/sdk' to v7 and '@azuro-org/toolkit' to v6 using npm, yarn, or pnpm.
```bash
npm install @azuro-org/sdk@^7 @azuro-org/toolkit@^6
# or
yarn add @azuro-org/sdk@^7 @azuro-org/toolkit@^6
# or
pnpm add @azuro-org/sdk@^7 @azuro-org/toolkit@^6
```
--------------------------------
### Usage Example: Betslip (Option B)
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/sdk/watch-hooks/useConditionsState/page.mdx
Example of usage for a betslip, passing condition IDs only.
```APIDOC
## Usage Example: Betslip (Option B)
```tsx
import { useConditionsState } from '@azuro-org/sdk'
import { ConditionState } from '@azuro-org/toolkit'
import { useMemo } from 'react'
const items = [{...}]
const { data: states, isFetching: isStatesFetching } = useConditionsState({
conditionIds: items.map(({ conditionId }) => conditionId),
})
const isConditionsInActiveState = useMemo(() => {
return Object.values(states).every(state => state === ConditionState.Active)
}, [ states ])
```
```
--------------------------------
### Setup Apollo Clients for Subgraphs
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/APIs/graph/use/page.mdx
Instantiate Apollo clients for both the client subgraph and the data-feed subgraph. Ensure you use the correct URIs for each.
```javascript
import { ApolloClient, InMemoryCache, HttpLink } from '@apollo/client';
// Client subgraph client
const clientSubgraphClient = new ApolloClient({
link: new HttpLink({
uri: 'https://thegraph.onchainfeed.org/subgraphs/name/azuro-protocol/azuro-api-polygon-v3',
}),
cache: new InMemoryCache(),
});
// Data-feed subgraph client
const dataFeedSubgraphClient = new ApolloClient({
link: new HttpLink({
uri: 'https://thegraph-1.onchainfeed.org/subgraphs/name/azuro-protocol/azuro-data-feed-polygon',
}),
cache: new InMemoryCache(),
});
```
--------------------------------
### Setting up LiveStatisticsSocketProvider and Watchers
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/sdk/watch-hooks/useLiveStatistics/page.mdx
Before using useLiveStatistics, ensure you initialize event watchers and the LiveStatisticsSocketProvider. This setup is automatically handled if you are using AzuroSDKProvider.
```tsx
import { ChainProvider, LiveStatisticsSocketProvider, useWatchers } from '@azuro-org/sdk'
export function Watchers() {
useWatchers()
return null
}
function Providers(props: { children: React.ReactNode }) {
const { children } = props
return (
{children}
)
}
```
--------------------------------
### LiquidityTree Organization Example
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/knowledge-hub/how-azuro-works/liquidity-tree/page.mdx
Illustrates the hierarchical structure of a LiquidityTree for storing 4 elements, showing the root node, intermediate nodes, and leaf nodes.
```text
+------------------------------------------+
| 1 (top node) |
+---------------------+--------------------+
| 2 | 3 |
+----------+----------+--------------------+
| 4 (leaf) | 5 | 6 | 7 |
+----------+----------+--------------------+
```
--------------------------------
### useBetsSummaryBySelection Hook Usage
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/sdk/data-hooks/useBetsSummaryBySelection/page.mdx
Example of how to import and use the useBetsSummaryBySelection hook in your application. It demonstrates passing necessary parameters like account, gameId, and gameState.
```APIDOC
## useBetsSummaryBySelection Hook
### Description
The `useBetsSummaryBySelection` Hook should be used if you want to show user's bets results on the game page for resolved markets. Check [`useResolvedMarkets`](useResolvedMarkets).
### Usage
```ts
import { useBetsSummaryBeSelection } from '@azuro-org/sdk'
const { data, isFetching } = useBetsSummaryBeSelection({
account: '...',
gameId: '...',
gameState: GameState.Resolved
})
```
### Props
```ts
{
account: Address
gameId: string
gameState: GameState
chainId?: ChainId
query?: QueryParameter
}
```
### ChainId Types
```ts
type ChainId =
| 100 // Gnosis
| 137 // Polygon
| 80002 // Polygon Amoy
| 88888 // Chiliz
| 88882 // Chiliz Spicy
| 8453 // Base
| 84532 // Base Sepolia
```
### Return Value
```ts
UseQueryResult>
```
```ts
import { type UseQueryResult } from '@tanstack/react-query'
```
```
--------------------------------
### Filter Data by Timestamps
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/APIs/graph/request-optimizations/page.mdx
For requests that don't require all historical data, filter by timestamps to speed up queries. Example: filter upcoming games by ensuring their start date is in the future.
```typescript
const nowInSeconds = Math.floor(Date.now() / 1000)
const where: Game_filter = {
startsAt_gt: nowInSeconds,
}
```
--------------------------------
### Initialize the Subgraph
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/guides/deploying-azuro-subgraph/page.mdx
Initialize a new subgraph. Replace , , and with your specific values.
```bash
graph create --node --deploy-key
```
--------------------------------
### SIWE Authentication Flow with Toolkit
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/releases/33-toolkit-6-2-sdk-7-3/page.mdx
Demonstrates the complete SIWE authentication process using toolkit utilities: requesting a nonce, building the message, signing, and verifying. Ensure wallet client and necessary imports are available.
```typescript
import { getAddress } from 'viem'
import { buildSiweMessage, getSiweNonce, verifySiwe } from '@azuro-org/toolkit'
const { nonce, issuedAt, expiresAt } = await getSiweNonce({
address,
affiliateId,
chainId,
domain,
uri,
})
const message = buildSiweMessage({
domain,
address: getAddress(address),
uri,
chainId,
nonce,
issuedAt,
expiresAt,
statement: 'Sign in to Azuro',
})
const signature = await walletClient.signMessage({ account: address, message })
const { token, expiresIn } = await verifySiwe({ chainId, message, signature })
```
--------------------------------
### Get Offers List
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/guides/freebets/third-party/page.mdx
Retrieves a list of all available freebet offers. This is a simple GET request authenticated with your API token.
```bash
curl -X 'GET' \
'https://api.onchainfeed.org/api/v1/public/bonus/external/offer/list' \
-H 'accept: application/json' \
-H 'x-bonus-api-token: api_token'
```
--------------------------------
### Initialize Contracts Object
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/toolkit/utils/setupContracts/page.mdx
Import and use the setupContracts function to initialize a contracts object with the addresses of different Azuro Protocol contracts. Ensure all required contract addresses are provided.
```typescript
import { setupContracts } from '@azuro-org/toolkit'
const contracts = setupContracts({
lp: '0x7043E4e1c4045424858ECBCED80989FeAfC11B36',
core: '0xA40F8D69D412b79b49EAbdD5cf1b5706395bfCf7',
relayer: '0x92a4e8Bc6B92a2e1ced411f41013B5FE6BE07613',
azuroBet: '0x0DEE52b98ba8326DaD4C346a4F806Fd871360a00',
cashout: '0xC6BB817a7f02874F360d135D880200A2E440207D',
})
```
--------------------------------
### Migration Steps
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/sdk/migration-v7/page.mdx
Step-by-step instructions for migrating to SDK v7.0.0, including dependency updates and specific hook replacements.
```APIDOC
## Migration Steps
Follow these steps to migrate your application to SDK v7.0.0:
### Step 1: Update Dependencies
```bash
npm install @azuro-org/sdk@^7 @azuro-org/toolkit@^6
# or
yarn add @azuro-org/sdk@^7 @azuro-org/toolkit@^6
# or
pnpm add @azuro-org/sdk@^7 @azuro-org/toolkit@^6
```
This will automatically install the required `@azuro-org/toolkit` v6.0.0.
### Step 2: Replace `useMaxBet` with `useBetCalculation`
Find all instances of `useMaxBet` in your codebase:
```bash
# Search for useMaxBet usage
grep -r "useMaxBet" src/
```
Replace each usage:
1. Import `useBetCalculation` instead of `useMaxBet`.
2. Add `account` parameter (from `useAccount()` hook).
3. Destructure both `minBet` and `maxBet` from the result.
4. Update any references from `data` to `data.maxBet`.
### Step 3: Update `useGames` Hook
1. Replace pagination parameters:
- Change `filter.limit` to `perPage`.
- Change `filter.offset` to `page` (note: page is 1-based).
- Remove `filter.maxMargin` and `filter.conditionsState` if used.
2. Update `filter.leagueSlug` if using arrays:
```tsx
// If you need multiple leagues, make separate calls or use filter on results
const leagues = ['premier-league', 'la-liga']
```
3. Update import and type:
```tsx
// Change from:
import { Game_OrderBy } from '@azuro-org/tookit'
// To:
import { GameOrderBy } from '@azuro-org/tookit'
```
4. Update return type handling:
```tsx
// Access games from the result object
const { data } = useGames(...)
const games = data?.games || []
```
### Step 4: Update `useConditions` Hook
1. Remove `filter`, `orderBy`, and `orderDir` parameters.
2. Add `onlyActiveOrStopped: true` if you were filtering for active conditions.
3. Update type imports if needed.
```
--------------------------------
### Create Combo Bet Usage Example
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/toolkit/bet/createComboBet/page.mdx
Demonstrates how to generate typed data for a combo bet, sign it with a wallet, and then submit it to the Azuro API using the `createBet` function. Ensure you have the necessary wallet client and Azuro Toolkit imports.
```typescript
import { getComboBetTypedData, createBet } from '@azuro-org/toolkit'
const typedData = getComboBetTypedData({
account: '0x...',
minOdds: '...',
amount: '...',
nonce: '...',
clientData: {...},
bets: [ {...}, {...} ],
})
const signature = await walletClient.data.signTypedData(typedData)
const createdOrder: CreateBetResponse = await createBet({
account: '0x...',
minOdds: '...',
amount: '...',
nonce: '...',
clientData: {...},
bets: [ {...}, {...} ],
signature,
})
```
--------------------------------
### Get Market and Selection Names
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/guides/advanced/prematch/get-bets-history/page.mdx
Import and use utility functions from `@azuro-org/dictionaries` to get human-readable names for markets and selections based on their outcome IDs.
```typescript
import { getMarketName, getSelectionName } from '@azuro-org/dictionaries'
const marketName = getMarketName({ outcomeId })
const selectionName = getSelectionName({ outcomeId })
```
--------------------------------
### Get Gas Information
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/APIs/backend/betting/page.mdx
Retrieves gas information required for placing a bet.
```APIDOC
## GET /api/v1/public/bet/gas-info
### Description
Retrieves gas information needed for bet transactions.
### Method
GET
### Endpoint
https://dev-api.onchainfeed.org/api/v1/public/bet/gas-info
### Parameters
#### Query Parameters
- **environment** (string) - Required - The environment for which to get gas info (e.g., "PolygonAmoyUSDT").
### Response
#### Success Response (200)
- An array of gas information objects.
- **relayerFeeAmount** (string) - The amount of relayer fee.
#### Response Example
```json
[
{
"relayerFeeAmount": "100000000000000000"
}
]
```
```
--------------------------------
### Initialization with Providers
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/sdk/watch-hooks/useConditionsState/page.mdx
Before utilizing `useConditionsState`, it is essential to initialize the `FeedSocketProvider` and `ConditionUpdatesProvider`.
```APIDOC
## Initialization
It is essential to initialize the `FeedSocketProvider` and `ConditionUpdatesProvider` before using `useConditionsState`.
```tsx
import {
ChainProvider,
FeedSocketProvider,
ConditionUpdatesProvider,
useWatchers,
} from '@azuro-org/sdk'
function Providers(props: { children: React.ReactNode }) {
const { children } = props
return (
{children}
)
}
```
```
--------------------------------
### GET /api/v1/public/bet/orders/{id}
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/protocol-v3/v3-migration-guide/page.mdx
Retrieves the status of a specific bet order using its ID.
```APIDOC
## GET /api/v1/public/bet/orders/{id}
### Description
Fetches the current status and details of a previously placed bet order using its unique identifier.
### Method
GET
### Endpoint
`/api/v1/public/bet/orders/{id}`
### Parameters
#### Path Parameters
- **id** (string) - Required - The unique identifier of the bet order.
### Response
#### Success Response (200)
- **id** (string) - The unique identifier of the order.
- **environment** (string) - The blockchain environment.
- **state** (string) - The current state of the order (e.g., "Pending", "Settled", "Cancelled").
- **betType** (string) - The type of bet (e.g., "Single", "Combo").
- **createdAt** (date) - Timestamp when the order was created.
- **updatedAt** (date) - Timestamp when the order was last updated.
- **core** (date) - Core timestamp related to the order.
- **bettor** (string) - The address of the bettor.
- **affiliate** (string) - The affiliate identifier, if any.
- **odds** (number) - The odds at which the bet was placed.
- **amount** (number) - The amount of the bet.
- **betId** (integer) - The internal ID of the bet.
- **txHash** (string) - The transaction hash associated with the order, if available.
- **error** (string) - Error code, if the order failed.
- **errorMessage** (string) - Detailed error message, if applicable.
### Response Example
```json
[
{
"id": "string",
"environment": "string",
"state": "string",
"betType": "string",
"createdAt": "date",
"updatedAt": "date",
"core": "date",
"bettor": "string",
"affiliate": "string",
"odds": 0,
"amount": 0,
"betId": 0,
"txHash": "string",
"error": "string",
"errorMessage": "string"
}
]
```
```
--------------------------------
### Using getBetStatus Utility
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/toolkit/bet/getBetStatus/page.mdx
Demonstrates how to use the getBetStatus utility with game states, order state, and graph status to determine the unified bet status. Import necessary types and functions from '@azuro-org/toolkit'.
```typescript
import { getBetStatus, BetStatus } from '@azuro-org/toolkit'
const games = [
{ state: GameState.Live, startsAt: '1234567890' },
]
const orderState = BetOrderState.Sent
const graphStatus = GraphBetStatus.Accepted
const status = getBetStatus({ games, orderState, graphStatus })
if (status === BetStatus.Live) {
console.log('Bet is live!')
}
```
--------------------------------
### Get actual sport IDs
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/guides/freebets/third-party/page.mdx
Retrieves a list of actual sport IDs available.
```APIDOC
## GET /api/v1/public/bonus/external/utils/markets-combinations/sports
### Description
Retrieves a list of actual sport IDs available.
### Method
GET
### Endpoint
/api/v1/public/bonus/external/utils/markets-combinations/sports
### Request Example
```bash
curl -X 'GET' \
'https://api.onchainfeed.org/api/v1/public/bonus/external/utils/markets-combinations/sports' \
-H 'accept: application/json' \
-H 'x-bonus-api-token: api_token'
```
### Response
#### Success Response (200)
- **ActualSportIdsResponse** (object) - Response object containing actual sport IDs. See [ActualSportIdsResponse](/hub/apps/guides/freebets/types#actualsportidsresponse) for details.
```
--------------------------------
### Auto Sign-In Configuration
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/sdk/auth/useAuth/page.mdx
Shows how to configure the useAuth hook to automatically attempt sign-in as soon as the wallet is connected, provided no cached token exists.
```typescript
const { token } = useAuth({
affiliate: '0x...',
autoSignIn: true,
})
```
--------------------------------
### Get Bonuses
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/guides/freebets/third-party/page.mdx
Retrieves a list of all distributed bonuses. Requires an API token for authorization.
```APIDOC
## GET /api/v1/public/bonus/external/list
### Description
Retrieves a list of all distributed bonuses.
### Method
GET
### Endpoint
/api/v1/public/bonus/external/list
### Response
#### Success Response (200)
- **BonusesResponse** (object) - A list of distributed bonuses.
```
--------------------------------
### Get unique markets combinations
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/guides/freebets/third-party/page.mdx
Retrieves unique market combinations for a given sport ID.
```APIDOC
## GET /api/v1/public/bonus/external/utils/markets-combinations
### Description
Retrieves unique market combinations for a given sport ID.
### Method
GET
### Endpoint
/api/v1/public/bonus/external/utils/markets-combinations
### Parameters
#### Query Parameters
- **sportId** (string) - Required - Sport ID
### Request Example
```bash
curl -X 'GET' \
'https://api.onchainfeed.org/api/v1/public/bonus/external/utils/markets-combinations?sportId=33' \
-H 'accept: application/json' \
-H 'x-bonus-api-token: api_token'
```
### Response
#### Success Response (200)
- **SportsUniqueMarketsCombinationsResponse** (object) - Response object containing unique market combinations. See [SportsUniqueMarketsCombinationsResponse](/hub/apps/guides/freebets/types#sportsuniquemarketscombinationsresponse) for details.
```
--------------------------------
### setupContracts Function
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/toolkit/utils/setupContracts/page.mdx
Initializes contracts with provided addresses and ABIs. It accepts an object with contract names as keys and their addresses as values. The function returns a structured Contracts object containing addresses and ABIs for each contract.
```APIDOC
## setupContracts
Creates contracts object with ABI.
### Usage
```ts
import { setupContracts } from '@azuro-org/toolkit'
const contracts = setupContracts({
lp: '0x7043E4e1c4045424858ECBCED80989FeAfC11B36',
core: '0xA40F8D69D412b79b49EAbdD5cf1b5706395bfCf7',
relayer: '0x92a4e8Bc6B92a2e1ced411f41013B5FE6BE07613',
azuroBet: '0x0DEE52b98ba8326DaD4C346a4F806Fd871360a00',
cashout: '0xC6BB817a7f02874F360d135D880200A2E440207D',
})
```
### Props
The `setupContracts` function accepts an object with the following properties:
- **lp** (Address) - Required - The address for the Liquidity Provider contract.
- **core** (Address) - Required - The address for the Core contract.
- **relayer** (Address) - Required - The address for the Relayer contract.
- **azuroBet** (Address) - Required - The address for the AzuroBet contract.
- **cashout** (Address) - Optional - The address for the Cashout contract.
### Return Value
The function returns a `Contracts` object with the following structure:
```ts
type Contracts = {
lp: {
address: Address
abi: typeof lpAbi
}
core: {
address: Address
abi: typeof coreAbi
}
relayer: {
address: Address
abi: typeof relayerAbi
}
azuroBet: {
address: Address
abi: typeof azuroBetAbi
},
cashout?: {
address: Address
abi: typeof cashoutAbi
}
}
```
```
--------------------------------
### GET /api/v1/public/bet/gas-info
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/protocol-v3/v3-migration-guide/page.mdx
Retrieves gas price information for the current network, essential for calculating relayer fees.
```APIDOC
## GET /api/v1/public/bet/gas-info
### Description
Returns gas price information for the current network. This data is required to determine the `relayerFeeAmount` when creating an order.
### Method
GET
### Endpoint
`/api/v1/public/bet/gas-info`
### Response
#### Success Response (200)
- **gasLimit** (integer) - The gas limit for transactions.
- **gasPrice** (integer) - The current gas price.
- **betTokenRate** (integer) - The exchange rate for the bet token.
- **gasPriceInBetToken** (integer) - The gas price denominated in the bet token.
- **slippage** (integer) - Slippage information (note: the new system does not use slippage for bets).
- **gasAmount** (integer) - The amount of gas used.
- **relayerFeeAmount** (string) - The calculated relayer fee amount.
- **beautyRelayerFeeAmount** (string) - A formatted relayer fee amount.
- **symbol** (string) - The symbol of the gas token.
- **decimals** (integer) - The number of decimals for the gas token.
### Response Example
```json
[
{
"gasLimit": 0,
"gasPrice": 0,
"betTokenRate": 0,
"gasPriceInBetToken": 0,
"slippage": 0,
"gasAmount": 0,
"relayerFeeAmount": "string",
"beautyRelayerFeeAmount": "string",
"symbol": "string",
"decimals": 0
}
]
```
```
--------------------------------
### Get Precalculated Cashouts Props
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/toolkit/cashout/getPrecalculatedCashouts/page.mdx
Defines the properties required for the `getPrecalculatedCashouts` function, including `chainId` and `conditionIds`.
```typescript
{
chainId: ChainId
conditionIds: string[]
}
```
--------------------------------
### Initialize AzuroSDKProvider
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/sdk/setup/page.mdx
Wrap your application with AzuroSDKProvider to initialize the SDK context. This component must be used inside a valid WagmiProvider context. Set the initialChainId to configure the SDK for a specific network.
```tsx
import { AzuroSDKProvider } from '@azuro-org/sdk'
import { WagmiProvider, createConfig } from 'wagmi'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { polygonAmoy } from 'viem/chains'
const wagmiConfig = createConfig(config)
const queryClient = new QueryClient()
function Providers(props: { children: React.ReactNode }) {
const { children } = props
return (
{children}
)
}
```
--------------------------------
### Get Pools List
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/guides/freebets/third-party/page.mdx
Retrieves a list of all available bonus pools. Requires an API token for authorization.
```APIDOC
## GET /api/v1/public/bonus/external/pool/list
### Description
Retrieves a list of all available bonus pools.
### Method
GET
### Endpoint
/api/v1/public/bonus/external/pool/list
### Response
#### Success Response (200)
- **PoolsResponse** (object) - A list of bonus pools.
```
--------------------------------
### Get Offers List
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/guides/freebets/third-party/page.mdx
Retrieves a list of all available freebet offers. Requires an API token for authorization.
```APIDOC
## GET /api/v1/public/bonus/external/offer/list
### Description
Retrieves a list of all available freebet offers.
### Method
GET
### Endpoint
/api/v1/public/bonus/external/offer/list
### Response
#### Success Response (200)
- **OffersResponse** (object) - A list of freebet offers.
```
--------------------------------
### useOutcome
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/releases/10-sdk-v1.0.0/page.mdx
The `useOutcome` hook now automatically fetches initial values for `initialOdds` or `initialStatus` if they are not provided. It also provides flags to indicate when these initial values are being fetched.
```APIDOC
## useOutcome
### Description
Automatically retrieves initial values for `initialOdds` or `initialStatus` if not provided. Includes flags to indicate fetching status.
### Parameters
#### Query Parameters
- **initialOdds** (number) - Optional - The initial odds value.
- **initialStatus** (string) - Optional - The initial status value.
### Response
#### Success Response (200)
- **isOddsFetching** (boolean) - Indicates if initial odds are being fetched.
- **isStatusFetching** (boolean) - Indicates if initial status is being fetched.
```
--------------------------------
### Fetch Navigation Structure
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/toolkit/feed/getNavigation/page.mdx
Use this function to retrieve the navigation structure for sports. Ensure you have the '@azuro-org/toolkit' package installed.
```typescript
import { getNavigation } from '@azuro-org/toolkit'
const sports = await getNavigation({
chainId: 137,
sportHub: 'sports',
})
```
--------------------------------
### GraphQL Query: Before V3
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/protocol-v3/v3-migration-guide/page.mdx
Example of separate GraphQL queries used before V3 for fetching different bet types.
```graphql
query PrematchBets {
bets(where: { type: Ordinar }) {
id
betId
# ...other fields
}
}
query LiveBets {
liveBets {
id
betId
# ...other fields
}
}
```
--------------------------------
### Wrap/Unwrap WXDAI with Viem
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/guides/advanced/prematch/place-a-bet/page.mdx
Example for wrapping XDAI to WXDAI or unwrapping WXDAI back to XDAI using Viem. This is relevant for Gnosis chain where native tokens are wrapped.
```typescript
// wagmi/viem example
txDto.to = '0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d'
// XDAI -> WXDAI
if (isWrap) {
txDto.value = rawAmount
txDto.data = encodeFunctionData({
abi: erc20ABI,
functionName: 'deposit',
})
}
// WXDAI -> XDAI
else {
txDto.data = encodeFunctionData({
abi: erc20ABI,
functionName: 'withdraw',
args: [ rawAmount ],
})
}
sendTransaction(txDto)
```
--------------------------------
### Create Cashout using Toolkit
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/guides/cashout/use-cashout/page.mdx
Utilize the Toolkit to first generate typed data for signing and then submit the cashout request. This method provides more control over the signing process.
```ts
import { getCashoutTypedData } from '@azuro-org/toolkit'
const typedData = getCashoutTypedData({
chainId: 137,
account: '0x...', // user's wallet address
attention: 'By signing this transaction, I agree to cash out on \'Azuro Example',
tokenId: 234n, // bet tokenId
cashoutOdds: 3135243n, // cashout odds from calculation
expiredAt: 2348238n, // cashout expiry date
})
// sign typed data with wallet client
const signature = await walletClient!.data!.signTypedData(typedData)
```
```ts
import { createCashout } from '@azuro-org/toolkit'
const createdCashout = await createCashout({
chainId: 137,
calculationId: '...', // calculation id from prev step
attention: 'By signing this transaction, I agree to cash out on \'Azuro Example',
signature,
})
```
--------------------------------
### useNativeBalance Hook Usage
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/sdk/hooks/useNativeBalance/page.mdx
Demonstrates how to import and use the useNativeBalance hook to get balance data and fetching status.
```APIDOC
## useNativeBalance Hook
Returns native balance based on [`appChain.id`](/hub/apps/sdk/providers/chain#return-value).
Hook represents a logic wrapper over Wagmi's `useBalance` hook. Explore [useBalance](https://wagmi.sh/react/api/hooks/useBalance#usebalance) to understand what data the hook returns.
### Usage
```ts
import { useNativeBalance } from '@azuro-org/sdk'
const { data, isFetching } = useNativeBalance()
const { rawBalance, balance } = data
```
### Props
```ts
{
chainId?: ChainId
query?: UseBalanceParameters['query']
}
```
### Return Value
```ts
UseBalanceReturnType<{
rawBalance: bigint;
balance: string;
}>
```
--------------------------------
### createBet Function
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/toolkit/bet/createBet/page.mdx
This snippet demonstrates how to use the `createBet` function from the Azuro Toolkit. It includes obtaining typed data for the bet, signing it with a wallet, and then calling `createBet` with the necessary parameters.
```APIDOC
## createBet
Creates a single (ordinary) bet by submitting signed bet data to the Azuro API.
This function sends the bet order to the relayer which will then place the bet on-chain.
### Usage
```ts
import { getBetTypedData, createBet } from '@azuro-org/toolkit'
const typedData = getBetTypedData({
account: '0xlkns...',
clientData: {...},
bet: {...},
})
const signature = await walletClient.data.signTypedData(typedData)
const createdOrder: CreateBetResponse = await createBet({
clientData: {...},
bet: {...},
signature,
})
```
### Props
- **clientData** (BetClientData) - Required - Data related to the bet client.
- **bet** (object) - Required - Bet details.
- **conditionId** (string | bigint) - Required - The ID of the condition.
- **outcomeId** (string | number | bigint) - Required - The ID of the outcome.
- **minOdds** (string | bigint) - Required - The minimum odds for the bet.
- **amount** (string | bigint) - Required - The amount to bet.
- **nonce** (string | number | bigint) - Required - The nonce for the bet.
- **signature** (Hex) - Required - The signed typed data.
- **bonusId** (string) - Optional - The freebet ID to place the bet with.
### BetClientData Type
```ts
type BetClientData = {
attention: string
affiliate: Address
core: Address
expiresAt: number
chainId: ChainId
relayerFeeAmount: string
isBetSponsored: boolean
isFeeSponsored: boolean
isSponsoredBetReturnable: boolean
}
```
### Return Value
- **CreateBetResponse** (object) - The response from creating a bet.
- **id** (string) - The unique identifier of the created bet order.
- **state** (BetOrderState) - The current state of the bet order.
- **errorMessage** (string) - Optional - An error message if the creation failed.
- **error** (string) - Optional - A general error indicator.
### BetOrderState Enum
Represents the lifecycle states of a bet order:
- **Created**: First status when created.
- **Placed**: Bet is included in the calculation of potential loss/wins.
- **Sent**: The relayer has been taken into processing to send the bet to the contracts.
- **Accepted**: Bet successfully accepted in the contracts.
- **Rejected**: An error occurred during the contracts checks.
- **PendingCancel**: The process of canceling the bet.
- **CancelFailed**: Cancellation error.
- **Canceled**: Bet is canceled.
- **Settled**: The bet is settled (won or lost).
```
--------------------------------
### Get actual leagues
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/guides/freebets/third-party/page.mdx
Retrieves a list of actual leagues, optionally filtered by sport IDs and time range.
```APIDOC
## GET /api/v1/public/bonus/external/utils/leagues
### Description
Retrieves a list of actual leagues, optionally filtered by sport IDs and time range.
### Method
GET
### Endpoint
/api/v1/public/bonus/external/utils/leagues
### Parameters
#### Query Parameters
- **sportIds** (array) - Optional - Array of sport IDs
- **startsAtFrom** (string) - Optional - From time (timestamp)
- **startsAtTo** (string) - Optional - To time (timestamp)
### Request Example
```bash
curl -X 'GET' \
'https://api.onchainfeed.org/api/v1/public/bonus/external/utils/leagues?sportIds=33&startsAtFrom=1742216019000&startsAtTo=1743339219000' \
-H 'accept: application/json' \
-H 'x-bonus-api-token: api_token'
```
### Response
#### Success Response (200)
- **ActualLeaguesResponse** (object) - Response object containing actual leagues. See [ActualLeaguesResponse](/hub/apps/guides/freebets/types#actualleaguesresponse) for details.
```
--------------------------------
### Create a Bet using Azuro Toolkit
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/toolkit/bet/createBet/page.mdx
Use this function to create a single bet. It requires pre-signed bet data. Ensure you have imported `getBetTypedData` and `createBet` from '@azuro-org/toolkit'.
```typescript
import { getBetTypedData, createBet } from '@azuro-org/toolkit'
const typedData = getBetTypedData({
account: '0xlkns...',
clientData: {...},
bet: {...},
})
const signature = await walletClient.data.signTypedData(typedData)
const createdOrder: CreateBetResponse = await createBet({
clientData: {...},
bet: {...},
signature,
})
```
--------------------------------
### Get Cashout Order using Toolkit
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/guides/cashout/use-cashout/page.mdx
Retrieves cashout order details using the `getCashout` function from the `@azuro-org/toolkit` library.
```APIDOC
## Get Cashout Order (Toolkit)
### Description
Retrieves the details of a specific cashout order using the `getCashout` function.
### Method Signature
`getCashout({ chainId: number, orderId: string }) => Promise
### Parameters
#### Path Parameters
- **chainId** (number) - Required - The ID of the blockchain network.
- **orderId** (string) - Required - The unique identifier of the cashout order.
### Request Example
```ts
import { getCashout } from '@azuro-org/toolkit'
const cashout = await getCashout({
chainId: 137,
orderId: createdCashout.id,
})
```
### Response
#### Success Response
- **CashoutOrder** - An object containing the cashout order details.
- **id** (string) - Cashout ID
- **state** (string) - Order state (PROCESSING, ACCEPTED, REJECTED, OPEN)
- **txHash** (string) - Transaction ID
- **error?** (string) - Error code (optional)
- **errorMessage?** (string) - Error message (optional)
```
--------------------------------
### useGameState Hook Usage
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/sdk/watch-hooks/useGameState/page.mdx
This example demonstrates how to use the useGameState hook to retrieve and display the current state of a game. It shows the necessary imports and how to pass gameId and initialState to the hook.
```APIDOC
## useGameState Hook
### Description
The `useGameState` hook is used for maintaining updated state for a game. It allows you to react to changes in the game's state, such as when it enters or exits prematch or stopped states.
### Props
- **gameId** (string) - Required - The unique identifier for the game.
- **initialState** (GameState) - Required - The initial state of the game.
### Return Value
- **data** (GameState) - The current state of the game.
### Example Usage
```tsx
import { useGameState } from '@azuro-org/sdk'
import { GameQuery } from '@azuro-org/toolkit'
type ContentProps = {
game: NonNullable
}
const Content: React.FC = ({ game }) => {
const { data: state } = useGameState({
gameId: game.gameId,
initialState: game.state,
})
return (
<>
>
)
}
```
### Prerequisites
Before using `useGameState`, ensure that `FeedSocketProvider` and `GameUpdatesProvider` are initialized:
```tsx
import { ChainProvider, FeedSocketProvider, GameUpdatesProvider } from '@azuro-org/sdk'
function Providers(props: { children: React.ReactNode }) {
return (
{props.children}
)
}
```
```
--------------------------------
### useBetFee Hook Usage
Source: https://github.com/azuro-protocol/gem-docs/blob/main/src/app/hub/apps/sdk/data-hooks/useBetFee/page.mdx
Demonstrates how to import and use the useBetFee hook in a React component to get bet fee data.
```APIDOC
## useBetFee Hook
### Description
This hook is used to fetch the relayer fee amount for a bet.
### Usage
```ts
import { useBetFee } from '@azuro-org/sdk'
const { data, isFetching, error } = useBetFee()
const { formattedRelayerFeeAmount } = data
```
### Props
```ts
{
chainId?: ChainId
query?: QueryParameterWithSelect
} | undefined
```
### Return Value
```ts
UseQueryResult<{
gasAmount: bigint
relayerFeeAmount: bigint
formattedRelayerFeeAmount: string
}>
```
### Type Definitions
```ts
type UseBetFeeQueryFnData = {
gasAmount: bigint
relayerFeeAmount: bigint
formattedRelayerFeeAmount: string
}
type ChainId =
| 100 // Gnosis
| 137 // Polygon
| 80002 // Polygon Amoy
| 88888 // Chiliz
| 88882 // Chiliz Spicy
| 8453 // Base
| 84532 // Base Sepolia
```
```