Skip to main content

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

question
string
required
The main question for the prediction market
description
string
required
Detailed description of the market and resolution criteria
possibleOutcomes
string[]
required
Array of possible outcomes (minimum 2 options)
resolutionTimestamp
number
required
Unix timestamp for when the market will be resolved (must be in the future)

Example Request

{
  "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

success
boolean
Indicates if the market was created successfully
marketId
string
The unique identifier for the created market
transactionHash
string
The blockchain transaction hash for the market creation
Success (200 OK)
{
  "success": true,
  "marketId": "123",
  "transactionHash": "0x..."
}

Error Responses

Bad Request (400)
{
  "success": false,
  "error": "Invalid or missing \"question\" field"
}
Internal Server Error (500)
{
  "success": false,
  "error": "Error message details"
}

Code Examples

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);
  }
}
The x402fetch library automatically handles the X402 payment flow and permit signatures. Manual construction of payment headers is not recommended.

Installation

Install the X402 SDK in your project:
npm
npm install x402-fetch
yarn
yarn add x402-fetch
pnpm
pnpm add x402-fetch

Important Notes

  • 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
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.

Next Steps