Skip to content

Quick Start (5 Minutes)

Get up and running with 4SEC API. No signup, no API keys, just your wallet.

Prerequisites

  • Python 3.9+ or Node.js 18+
  • Crypto wallet with USDC on Base network

Step 1: Install x402 Client

bash
# Python
pip install x402-client httpx eth-account

# JavaScript
npm install @x402/client ethers

Step 2: Setup Wallet

python
from eth_account import Account
from x402.client import X402Client

wallet = Account.from_key("0x_your_private_key_here")
client = X402Client(wallet=wallet, facilitator_url="https://x402.org/facilitator")

Step 3: First Request

python
response = client.get("https://api.foursec.xyz/price/ETH")
data = response.json()

print(f"Symbol: {data['symbol']}")
print(f"Price: ${data['price_usd']}")
print(f"24h Change: {data['change_24h']}%")
print(f"Sources: {data['total_sources']} DEXes")

Expected Response

json
{
  "symbol": "ETH",
  "price_usd": 2450.32,
  "change_24h": 2.45,
  "volume_24h_usd": 12500000,
  "total_sources": 3,
  "spread": 0.07,
  "sources": [
    {"dex": "Uniswap V3", "price": 2450.30, "liquidity_usd": 5200000},
    {"dex": "BaseSwap", "price": 2450.35, "liquidity_usd": 3100000},
    {"dex": "SushiSwap", "price": 2450.28, "liquidity_usd": 4200000}
  ]
}

Step 4: Try More Endpoints

python
# Arbitrage opportunities ($0.03)
arb = client.get("https://api.foursec.xyz/arbitrage-opportunity").json()

# Historical data ($0.02)
history = client.get("https://api.foursec.xyz/price/history/ETH?interval=1h&limit=24").json()

# Risk metrics ($0.02)
risk = client.get("https://api.foursec.xyz/volatility-index/ETH").json()

What Just Happened?

  1. You sent GET request to the API
  2. API returned 402 Payment Required
  3. x402 client automatically signed USDC transfer
  4. Client retried with payment proof
  5. API verified and returned data
  6. Total cost: $0.01 USDC

INFO

Same request within 30s is free (served from cache).

Next Steps

Released under the MIT License.