> ## Documentation Index
> Fetch the complete documentation index at: https://docs.delphai.io/llms.txt
> Use this file to discover all available pages before exploring further.

# X402 API

> Create prediction markets programmatically using the DelphAI X402 API

## Overview

The DelphAI X402 API allows you to create prediction markets programmatically. Each API call costs **1 WLFI USD** (World Liberty Financial USD) paid via the X402 protocol.

## Endpoint

```
POST https://api.delphai.io/create_market
```

## Authentication

This endpoint requires a payment of **1 WLFI USD** via X402 protocol for each call. The payment is handled automatically through the X402 SDK using ERC-2612 permit signatures.

**Payment Details:**

* **Token:** WLFI USD (World Liberty Financial USD)
* **Symbol:** USD1
* **Amount:** 1 WLFI (1000000000000000000 wei)
* **Network:** BSC (Binance Smart Chain)
* **Token Address:** `0x8d0D000Ee44948FC98c9B98A4FA4921476f08B0d`

## Request

### Request Body

<ParamField body="question" type="string" required>
  The main question for the prediction market
</ParamField>

<ParamField body="description" type="string" required>
  Detailed description of the market and resolution criteria
</ParamField>

<ParamField body="possibleOutcomes" type="string[]" required>
  Array of possible outcomes (minimum 2 options)
</ParamField>

<ParamField body="resolutionTimestamp" type="number" required>
  Unix timestamp for when the market will be resolved (must be in the future)
</ParamField>

### Example Request

```json theme={null}
{
  "question": "Will Bitcoin reach $100k by end of 2024?",
  "description": "This market resolves to YES if Bitcoin (BTC) reaches $100,000 USD on any major exchange before December 31, 2024 23:59:59 UTC.",
  "possibleOutcomes": ["Yes", "No"],
  "resolutionTimestamp": 1735689599
}
```

## Response

### Success Response

<ResponseField name="success" type="boolean">
  Indicates if the market was created successfully
</ResponseField>

<ResponseField name="marketId" type="string">
  The unique identifier for the created market
</ResponseField>

<ResponseField name="transactionHash" type="string">
  The blockchain transaction hash for the market creation
</ResponseField>

```json Success (200 OK) theme={null}
{
  "success": true,
  "marketId": "123",
  "transactionHash": "0x..."
}
```

### Error Responses

```json Bad Request (400) theme={null}
{
  "success": false,
  "error": "Invalid or missing \"question\" field"
}
```

```json Internal Server Error (500) theme={null}
{
  "success": false,
  "error": "Error message details"
}
```

## Code Examples

<CodeGroup>
  ```typescript TypeScript/JavaScript theme={null}
  import { x402fetch } from 'x402-fetch';

  async function createMarket() {
    const response = await x402fetch('https://api.delphai.io/create_market', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        question: 'Will Bitcoin reach $100k by end of 2024?',
        description: 'This market resolves to YES if Bitcoin (BTC) reaches $100,000 USD on any major exchange before December 31, 2024 23:59:59 UTC.',
        possibleOutcomes: ['Yes', 'No'],
        resolutionTimestamp: 1735689599
      })
    });

    const data = await response.json();

    if (data.success) {
      console.log('Market created!', data.marketId);
      console.log('Transaction:', data.transactionHash);
    } else {
      console.error('Error:', data.error);
    }
  }
  ```

  ```bash cURL theme={null}
  curl -X POST https://api.delphai.io/create_market \
    -H "Content-Type: application/json" \
    -H "X-PAYMENT: <x402_payment_data>" \
    -d '{
      "question": "Will Bitcoin reach $100k by end of 2024?",
      "description": "This market resolves to YES if Bitcoin (BTC) reaches $100,000 USD on any major exchange before December 31, 2024 23:59:59 UTC.",
      "possibleOutcomes": ["Yes", "No"],
      "resolutionTimestamp": 1735689599
    }'
  ```
</CodeGroup>

<Note>
  The `x402fetch` library automatically handles the X402 payment flow and permit signatures. Manual construction of payment headers is not recommended.
</Note>

## Installation

Install the X402 SDK in your project:

```bash npm theme={null}
npm install x402-fetch
```

```bash yarn theme={null}
yarn add x402-fetch
```

```bash pnpm theme={null}
pnpm add x402-fetch
```

## Important Notes

<Warning>
  * Each API call costs **1 WLFI USD** paid via X402 protocol on BSC
  * The `resolutionTimestamp` must be in the future
  * A minimum of 2 `possibleOutcomes` is required
  * Markets are published on-chain and cannot be deleted
  * Payment is automatically verified before the market is created
</Warning>

<Tip>
  The X402 protocol uses ERC-2612 permit signatures, which means users don't need to make a separate token approval transaction. The payment is gasless from the user's perspective.
</Tip>

## Next Steps

<CardGroup cols={2}>
  <Card title="Prediction Markets" icon="chart-line" href="/core-concepts/prediction-markets">
    Learn more about how prediction markets work
  </Card>

  <Card title="Market Lifecycle" icon="circle-notch" href="/core-concepts/market-lifecycle">
    Understand the market lifecycle and resolution process
  </Card>
</CardGroup>
