Prerequisites
- Node.js 18+ with TypeScript support
- An Ethereum wallet (or you will generate one in Step 1)
- USDC on Base mainnet (~$5 to cover gas and several market creations)
Step 1: Set up a Base L2 wallet
Your agent needs a dedicated EVM wallet whose private key it can access at runtime for signing. You can generate a fresh wallet programmatically:Step 2: Fund the wallet with USDC on Base
The x402 endpoints use USDC on Base mainnet (CAIP-2 identifier:eip155:8453). Your wallet needs:
- $1.00 USDC minimum per market creation call
- A small amount of ETH on Base for gas (typically 0.05 per transaction)
- A buffer for other x402 endpoints if you plan to use them (
feed,oracle/resolve)
Step 3: Apply for creator access
Creator approval is a one-time, per-wallet step. Without it,POST /x402/markets returns 403 after charging you $1 — apply first.
- Visit blockforecast.io/apply.
- Click Connect wallet and choose External wallet.
- Connect using the agent wallet’s address (use WalletConnect with any wallet holding the key, or paste the address and sign manually).
- Complete the application form — describe your use case and confirm the wallet address.
- You will hear back within 24 hours. Creator approval covers the web UI,
POST /public/markets, andPOST /x402/marketsfrom the same wallet.
You only do this once per agent wallet. After approval, the wallet can create markets indefinitely across all BlockForecast surfaces.
Step 4: POST /x402/markets
With a funded, approved wallet, you are ready to create a market. Thex402-fetch library handles the entire 402 round-trip for you — it sends the initial request, parses the payment requirements, constructs and signs the EIP-3009 transferWithAuthorization, and retries with the X-PAYMENT header automatically.
Full working example
What x402-fetch does under the hood
If you prefer to implement the protocol directly (for a different language or a custom client), here is the manual flow:Response: the created market object
A successful201 Created response returns the new market:
https://blockforecast.io/market/{slug}. Creator fee earnings (0.5% of every trade) flow to account.address in real time.
Error handling
| HTTP status | Condition | What to do |
|---|---|---|
402 Payment Required | Initial response — no payment sent | Expected behavior. Client must sign and retry. |
402 Payment Required (retry) | Payment was invalid or nonce was reused | Construct a fresh payment authorization with a new nonce and retry. |
403 Forbidden | Paying wallet does not have creator approval | Apply for creator access before calling this endpoint. Payment is not refunded. |
400 Bad Request | Request body failed validation | Check the errors array in the response body for field-level details. |
402 with INSUFFICIENT_FUNDS | Wallet USDC balance too low | Fund the wallet with more USDC on Base mainnet. |
503 Service Unavailable | CDP facilitator temporarily unreachable | Retry with exponential backoff. The payment was not settled. |
To monitor your agent’s market performance and creator earnings, use
GET /api/v2/public/balance (with your standard API key) or query the on-chain USDC balance of the agent address directly via any Base L2 RPC.