# Play To Earn Contract

## Overview

The `P2EGame` (Play-to-Earn Game) contract is designed for managing a gaming ecosystem where players can stake ERC20 tokens in a gaming escrow.&#x20;

The contract handles the staking of tokens, tracks game states, and manages token payouts based on game outcomes.

## Methods

## <mark style="color:blue;">`gameState`</mark>

Retrieves the current state of game funds in escrow.

### Parameters

| **Parameter** | **Type**  | **Description**         |
| ------------- | --------- | ----------------------- |
| `_gameId`     | `uint256` | Identifier of the game. |
| `_player`     | `address` | Address of the player.  |

### Returns

| **Return** | **Type**                   | **Description**                             |
| ---------- | -------------------------- | ------------------------------------------- |
| Tuple      | `(uint256, bool, address)` | Balance, lock status, and treasury address. |

## <mark style="color:blue;">`createGame`</mark>

### Parameters

| **Parameter** | **Type**  | **Description**                |
| ------------- | --------- | ------------------------------ |
| `_player`     | `address` | Address of the player.         |
| `_treasury`   | `address` | Treasury address for the game. |
| `_p`          | `uint256` | Player's staked amount.        |
| `_t`          | `uint256` | Treasury's staked amount.      |

### Returns

| **Return** | **Type** | **Description**                                   |
| ---------- | -------- | ------------------------------------------------- |
| `success`  | `bool`   | Returns true if the game is successfully created. |

## <mark style="color:blue;">`playerWon`</mark>

### Parameters

| **Parameter** | **Type**  | **Description**                |
| ------------- | --------- | ------------------------------ |
| `_gameId`     | `uint256` | Identifier of the game.        |
| `_player`     | `address` | Address of the winning player. |

### Returns

| **Return** | **Type** | **Description**                                   |
| ---------- | -------- | ------------------------------------------------- |
| `success`  | `bool`   | Returns true if tokens are unlocked successfully. |

## <mark style="color:blue;">`playerLost`</mark>

### Parameters

| **Parameter** | **Type**  | **Description**               |
| ------------- | --------- | ----------------------------- |
| `_gameId`     | `uint256` | Identifier of the game.       |
| `_player`     | `address` | Address of the losing player. |

### Returns

| **Return** | **Type** | **Description**                             |
| ---------- | -------- | ------------------------------------------- |
| `success`  | `bool`   | Returns true if funds are sent to treasury. |

## <mark style="color:blue;">`Withdraw`</mark>

### Parameters

| **Parameter** | **Type**  | **Description**         |
| ------------- | --------- | ----------------------- |
| `_gameId`     | `uint256` | Identifier of the game. |

### Returns

| **Return** | **Type** | **Description**                           |
| ---------- | -------- | ----------------------------------------- |
| `success`  | `bool`   | Returns true if withdrawal is successful. |


---

# 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.volary.io/template-library/smart-contracts/play-to-earn-contract.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.
