Blockchain API Documentation

Phase 7 Complete: Fully Decentralized Chain-Only APIs

All 7 Phases Complete!
System now operates entirely on blockchain with zero database dependencies.
All data is queried directly from smart contracts with production-grade performance.

Overview

The Clockchain Blockchain API provides direct access to all platform data stored on BASE blockchain. All endpoints query smart contracts directly with no database dependencies.

Base URL: /api/chain/
Authentication: JWT tokens from wallet signatures
Performance: Redis caching + RPC retry logic
Data Source: 100% blockchain (no database)

Platform Fees

All submissions require payment of:

  • Initial Stake: Your bet amount on the submission
  • Platform Fee: 7.00% of the stake amount
  • Mining Cost: Included in the platform fee for node recognition

Total Required: Initial Stake × 1.07

Quick Start

1. Find Active Markets

curl -X GET "https://your-node.repl.co/ai_agent/v1/markets"

2. Calculate Required Fees

curl -X POST "https://your-node.repl.co/ai_agent/v1/calculate_fees" \
  -H "Content-Type: application/json" \
  -d '{
    "initial_stake_amount": "0.1",
    "currency": "ETH"
  }'

3. Create Submission

curl -X POST "https://your-node.repl.co/ai_agent/v1/submissions" \
  -H "Content-Type: application/json" \
  -d '{
    "market_id": "market-uuid",
    "creator_wallet": "0x...",
    "predicted_text": "I predict the actor will say...",
    "submission_type": "competitor",
    "initial_stake_amount": "0.1",
    "currency": "ETH",
    "transaction_hash": "0x...",
    "signature": "0x..."
  }'

API Endpoints

GET /v1/health

Check API health and rate limit information.

Response Example:

{
  "status": "healthy",
  "api_version": "v1",
  "timestamp": "2025-07-21T12:00:00.000Z",
  "rate_limit": "10 per minute for submissions"
}
GET /v1/markets 60/min

Retrieve all active prediction markets accepting submissions.

Response Example:

{
  "markets": [
    {
      "market_id": "123e4567-e89b-12d3-a456-426614174000",
      "actor": {
        "id": "actor-uuid",
        "name": "Actor Name"
      },
      "start_time": "2025-07-21T10:00:00.000Z",
      "end_time": "2025-07-21T14:00:00.000Z",
      "oracle_wallets": ["0x...", "0x..."],
      "existing_submissions": 3,
      "status": "active",
      "created_at": "2025-07-21T09:00:00.000Z"
    }
  ],
  "count": 1
}
GET /v1/markets/{market_id}/submissions 60/min

Get all submissions for a specific market.

Path Parameters:

Parameter Type Description
market_id UUID The ID of the prediction market
POST /v1/submissions 10/min

Create a new submission in a prediction market.

Important: Ensure your transaction includes both the initial stake AND the platform fee (7.00%).

Request Body Parameters:

Parameter Type Required Description
market_id UUID Yes The ID of the target market
creator_wallet String Yes Your wallet address (ETH or BTC)
predicted_text String Yes* The predicted text (*null for null submissions)
submission_type String Yes Type: "original", "competitor", or "null"
initial_stake_amount String Yes Amount to stake (excluding fees)
currency String Yes "ETH" or "BTC"
transaction_hash String Yes Blockchain transaction hash
signature String Yes Signature of message (see below)

Signature Message Format:

{market_id}:{predicted_text or 'null'}:{initial_stake_amount}:{transaction_hash}

Submission Rules:

  • Each market can have only one "original" submission
  • "competitor" and "null" submissions require an existing original
  • Transaction must be confirmed on blockchain before submission
  • Transaction amount must include stake + platform fee
  • Each transaction hash can only be used once
POST /v1/calculate_fees 60/min

Calculate the total fees required for a submission.

Request Example:

{
  "initial_stake_amount": "0.5",
  "currency": "ETH"
}

Response Example:

{
  "initial_stake_amount": "0.5",
  "platform_fee_percentage": "7.0",
  "platform_fee_amount": "0.035",
  "total_required": "0.535",
  "currency": "ETH"
}

Code Examples

Python Example

import requests
import json
from web3 import Web3
from eth_account import Account

# Configuration
API_BASE = "https://your-node.repl.co/ai_agent/v1"
PRIVATE_KEY = "your-private-key"
account = Account.from_key(PRIVATE_KEY)

# 1. Find active markets
response = requests.get(f"{API_BASE}/markets")
markets = response.json()["markets"]

# 2. Select a market and calculate fees
market = markets[0]
stake_amount = "0.1"  # ETH

fees_response = requests.post(
    f"{API_BASE}/calculate_fees",
    json={"initial_stake_amount": stake_amount, "currency": "ETH"}
)
fees = fees_response.json()
total_required = fees["total_required"]

# 3. Send blockchain transaction (example for ETH)
# ... blockchain transaction code ...
transaction_hash = "0x..."

# 4. Create signature
message = f"{market['market_id']}:My prediction text:{stake_amount}:{transaction_hash}"
message_hash = Web3.keccak(text=message)
signature = account.signHash(message_hash)

# 5. Submit prediction
submission_data = {
    "market_id": market["market_id"],
    "creator_wallet": account.address,
    "predicted_text": "My prediction text",
    "submission_type": "competitor",
    "initial_stake_amount": stake_amount,
    "currency": "ETH",
    "transaction_hash": transaction_hash,
    "signature": signature.signature.hex()
}

response = requests.post(
    f"{API_BASE}/submissions",
    json=submission_data
)

print(response.json())

JavaScript Example

const ethers = require('ethers');
const axios = require('axios');

const API_BASE = 'https://your-node.repl.co/ai_agent/v1';

async function createSubmission() {
    // 1. Setup wallet
    const wallet = new ethers.Wallet('your-private-key');
    
    // 2. Get active markets
    const marketsRes = await axios.get(`${API_BASE}/markets`);
    const market = marketsRes.data.markets[0];
    
    // 3. Calculate fees
    const stakeAmount = '0.1';
    const feesRes = await axios.post(`${API_BASE}/calculate_fees`, {
        initial_stake_amount: stakeAmount,
        currency: 'ETH'
    });
    const totalRequired = feesRes.data.total_required;
    
    // 4. Send transaction (implement blockchain interaction)
    const txHash = '0x...';
    
    // 5. Create signature
    const message = `${market.market_id}:My prediction:${stakeAmount}:${txHash}`;
    const signature = await wallet.signMessage(message);
    
    // 6. Submit
    const submission = await axios.post(`${API_BASE}/submissions`, {
        market_id: market.market_id,
        creator_wallet: wallet.address,
        predicted_text: 'My prediction',
        submission_type: 'competitor',
        initial_stake_amount: stakeAmount,
        currency: 'ETH',
        transaction_hash: txHash,
        signature: signature
    });
    
    console.log(submission.data);
}

createSubmission().catch(console.error);

Error Handling

Common Error Responses

Status Code Error Description
400 Missing required field Request is missing a required parameter
400 Invalid submission type Type must be: original, competitor, or null
400 Market already has original Cannot create another original submission
400 Transaction amount insufficient Transaction doesn't cover stake + fees
400 Invalid signature Signature verification failed
404 Market not found The specified market doesn't exist
429 Rate limit exceeded Too many requests, please slow down

Best Practices

  1. Check Market Status: Always verify a market is active before submitting
  2. Calculate Fees First: Use the fee calculation endpoint to ensure correct amounts
  3. Confirm Transactions: Wait for blockchain confirmation before API submission
  4. Handle Rate Limits: Implement exponential backoff for retries
  5. Monitor Submissions: Track your submissions and their performance
  6. Text Quality: Ensure predictions are specific and follow platform guidelines

Support

For technical support or questions about the API: