> For the complete documentation index, see [llms.txt](https://docs.pretoke.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pretoke.xyz/api-reference/settlement.md).

# Settlement (Deposits, Withdrawals, Redemption)

{% hint style="warning" %}
**All endpoints require authentication.** See [How Trades Settle On-Chain](/how-it-works/settlement-explained.md) for conceptual background.
{% endhint %}

***

## GET /deposit-address

Returns your personal TON deposit address, allocating one on first call.

### Code examples

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

```bash
curl -X GET "https://predict.pretoke.xyz/api/v1/deposit-address" \
  -H "Authorization: Bearer <token>"
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const response = await fetch('https://predict.pretoke.xyz/api/v1/deposit-address', {
  headers: { 'Authorization': `Bearer ${accessToken}` }
});
const { data } = await response.json();
console.log(`Deposit to: ${data.address}`);
```

{% endtab %}

{% tab title="Python" %}

```python
response = requests.get(
    "https://predict.pretoke.xyz/api/v1/deposit-address",
    headers={"Authorization": f"Bearer {access_token}"}
)
deposit = response.json()["data"]
print(f"Deposit to: {deposit['address']}")
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const { data: result } = await axios.get('https://predict.pretoke.xyz/api/v1/deposit-address', {
  headers: { Authorization: `Bearer ${accessToken}` }
});
console.log('Deposit address:', result.data.address);
```

{% endtab %}
{% endtabs %}

### Response `200 OK`

```json
{
  "data": {
    "address": "UQAbc...def",
    "jettonWalletAddress": "UQxyz...abc",
    "derivationIndex": 42
  },
  "requestId": "..."
}
```

| Field                 | Description                                                                                       |
| --------------------- | ------------------------------------------------------------------------------------------------- |
| `address`             | Your deposit address, in non-bounceable friendly form (network-aware: testnet/mainnet prefix)     |
| `jettonWalletAddress` | The USDT Jetton wallet address associated with this deposit address (`null` before first deposit) |
| `derivationIndex`     | HD wallet derivation index (internal bookkeeping)                                                 |

{% hint style="danger" %}
**Only send USDT on the TON network** to this address. Sending TON coin itself, or USDT from a different blockchain, will not be credited automatically.
{% endhint %}

***

## POST /withdraw

Withdraw available balance to your connected wallet address.

### Request body

| Field    | Type   | Description                       |
| -------- | ------ | --------------------------------- |
| `amount` | string | Amount to withdraw, in micro-USDT |

{% hint style="info" %}
**Security:** The destination is always the wallet address bound to your authenticated session. There is no `walletAddress` field in the request — the gateway forcibly uses the address from your verified JWT, preventing redirection to an attacker's wallet.
{% endhint %}

### Code examples

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

```bash
curl -X POST "https://predict.pretoke.xyz/api/v1/withdraw" \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{ "amount": "500000000" }'
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const response = await fetch('https://predict.pretoke.xyz/api/v1/withdraw', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${accessToken}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ amount: '500000000' })
});
const { data } = await response.json();
console.log(`Status: ${data.status}, TX: ${data.txHash}`);
```

{% endtab %}

{% tab title="Python" %}

```python
response = requests.post(
    "https://predict.pretoke.xyz/api/v1/withdraw",
    headers={"Authorization": f"Bearer {access_token}"},
    json={"amount": "500000000"}
)
result = response.json()["data"]
print(f"Status: {result['status']}, TX: {result.get('txHash')}")
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const { data: result } = await axios.post(
  'https://predict.pretoke.xyz/api/v1/withdraw',
  { amount: '500000000' },
  { headers: { Authorization: `Bearer ${accessToken}` } }
);
console.log(result.data);
```

{% endtab %}
{% endtabs %}

### Response `202 Accepted`

```json
{
  "data": {
    "status": "accepted",
    "txHash": "e4f1a2...",
    "message": "Withdrawal submitted"
  },
  "requestId": "..."
}
```

| Status      | Meaning                                                            |
| ----------- | ------------------------------------------------------------------ |
| `accepted`  | Submitted on-chain; `txHash` is the TON transaction hash           |
| `duplicate` | An identical withdrawal is already in flight; nothing new was sent |
| `failed`    | Submission failed; `message` explains why                          |

***

## POST /redeem/:marketId

Redeem winning positions for a resolved market, converting them into a USDT payout.

### Path parameters

| Param      | Description                                  |
| ---------- | -------------------------------------------- |
| `marketId` | The resolved market to redeem positions from |

### Request body

| Field         | Type      | Description                                                          |
| ------------- | --------- | -------------------------------------------------------------------- |
| `conditionId` | string    | Hex-encoded on-chain condition ID for this market                    |
| `indexSets`   | string\[] | Hex-encoded index sets identifying which outcome positions to redeem |

### Code examples

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

```bash
curl -X POST "https://predict.pretoke.xyz/api/v1/redeem/mkt_01hz..." \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "conditionId": "3af9c1...",
    "indexSets": ["01", "02"]
  }'
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const response = await fetch('https://predict.pretoke.xyz/api/v1/redeem/mkt_01hz...', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${accessToken}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    conditionId: '3af9c1...',
    indexSets: ['01', '02']
  })
});
const { data } = await response.json();
console.log(`Redemption: ${data.status}`);
```

{% endtab %}

{% tab title="Python" %}

```python
response = requests.post(
    "https://predict.pretoke.xyz/api/v1/redeem/mkt_01hz...",
    headers={"Authorization": f"Bearer {access_token}"},
    json={"conditionId": "3af9c1...", "indexSets": ["01", "02"]}
)
result = response.json()["data"]
print(f"Redemption: {result['status']}")
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const { data: result } = await axios.post(
  'https://predict.pretoke.xyz/api/v1/redeem/mkt_01hz...',
  { conditionId: '3af9c1...', indexSets: ['01', '02'] },
  { headers: { Authorization: `Bearer ${accessToken}` } }
);
```

{% endtab %}
{% endtabs %}

### Response `202 Accepted`

```json
{
  "data": { "status": "accepted", "message": "Redemption submitted" },
  "requestId": "..."
}
```

{% hint style="info" %}
Both `/withdraw` and `/redeem` are deduplicated server-side — resubmitting an identical request while the original is in flight returns `"status": "duplicate"` without double-processing.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.pretoke.xyz/api-reference/settlement.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
