# Smart Contracts

Using our contract infrastructure, developers can:

* Analyze betting trends and access transparent odds, volume and game result data
* Deploy a hedging contract for players to hedge parlays automatically&#x20;
* Develop a frontend on existing Betonchain contracts
* Capture contract events to stream on social platforms
* Deploy and fund our [NFT voucher](#nft-vouchers) contracts to host risk-free bets for holders&#x20;
* And more!

<figure><img src="https://2353507963-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQ3KwiddvL0xnPd4jFvq6%2Fuploads%2F9bdOVL4i7gRj3SbrcMUe%2FScreen%20Shot%202023-07-05%20at%202.31.27%20PM.png?alt=media&#x26;token=258eaa1e-b5bd-4b50-89c5-e9b5099fd2d3" alt=""><figcaption><p>Screen Shot from the Betonchain Node's Chainlink Operator UI</p></figcaption></figure>

## Child Bet Contracts

You can access a wallet's bets by calling the functions below. The structs referenced below are`MoneyLineBetJoin`, `OverUnderBetJoin` and`PointSpreadBetJoin`. For relevant events see the [Events](#events) section.

## NFT Vouchers

Anyone can deploy and fund our NFT Voucher contracts to host risk-free bets for a specified scope of holders. The vouchers are compatible with both `ERC721` and `ERC1155` contract types.&#x20;

* The vouchers can be updated by their deployer and optionally support an array of IDs that allow subsets of NFT holders to qualify.&#x20;
* Vouchers accept funding in USDC, USDT or DAI for distributing risk-free bets after they're placed by qualified users through the Betonchain protocol.&#x20;
* The amount to distribute per bet and the interval over which to do so are required parameters. For example, one can specify that up to 100 USDC should be distributed in risk-free bets every 24 hours until funding is depleted.

Please [reach out ](https://discord.gg/FdUWQa7vE7)on our Discord for more details on NFT Vouchers and assistance with configuration and deployment.

## Events

{% hint style="info" %}
The official DApp displays an event stream: <https://betonchain.gg/activity>
{% endhint %}

### Examples

{% tabs %}
{% tab title="Python" %}

```python
import web3
import json

# endpoint, address, abi
PROVIDER_ENDPOINT = "https://eth-sepolia.g.alchemy.com/v2/..." 
CONTRACT_ADDRESS = "0x..."
with open("<abi_file_path>.json") as f:
    CONTRACT_ABI = json.load(f)
    
# web3 client
w3 = web3.Web3(web3.Web3.HTTPProvider(PROVIDER_ENDPOINT))

# example using BetML.sol contract 
ml_ct = w3.eth.contract(address=CONTRACT_ADDRESS, abi=CONTRACT_ABI)
ml_filter_results = ml_ct.events.MLBetResult.create_filter(fromBlock='latest')
ml_bet_results = ml_filter_results.get_all_entries()
# print logs
for log in ml_bet_results:
    print(log['args'], log['event'])
```

{% endtab %}
{% endtabs %}

### event RequestGameIdInit()

```solidity
/* BetConsumer.sol */
event RequestGameIdInit(bytes32 indexed requestId, uint256 game_id);
```

An event emitted when `fulfillInitGame()` executes successfully.&#x20;

| Parameter   | Type            | Description                                        |
| ----------- | --------------- | -------------------------------------------------- |
| `requestId` | bytes32 indexed | Request ID of the data request that was fulfilled  |
| `game_id`   | uint256         | Game ID of the game for which data was initialized |

### event RequestGameIdOdds()

```solidity
/* BetConsumer.sol */
event RequestGameIdOdds(bytes32 indexed requestId, uint256 game_id);
```

An event emitted when `fulfillOdds()` executes successfully.&#x20;

| Parameter   | Type            | Description                                        |
| ----------- | --------------- | -------------------------------------------------- |
| `requestId` | bytes32 indexed | Request ID of the data request that was fulfilled  |
| `game_id`   | uint256         | Game ID of the game for which data was initialized |

### event RequestGameIdResults()

```solidity
/* BetConsumer.sol */
event RequestGameIdResults(bytes32 indexed requestId, uint256 game_id);
```

An event emitted when `fulfillResults()` executes successfully.&#x20;

| Parameter   | Type            | Description                                        |
| ----------- | --------------- | -------------------------------------------------- |
| `requestId` | bytes32 indexed | Request ID of the data request that was fulfilled  |
| `game_id`   | uint256         | Game ID of the game for which data was initialized |

### event GameAdded()

```solidity
/* BetCore.sol */
event GameAdded(uint256 gameId, string league);
```

An event emitted when `_addGame()` executes successfully.

| Parameter | Type    | Description                                    |
| --------- | ------- | ---------------------------------------------- |
| `gameId`  | uint256 | Game ID of the game that was added for betting |
| `league`  | string  | League of the game that was added for betting  |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.betonchain.gg/platform-reference/developers/smart-contracts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
