Execute real blockchain transactions through the Elsa pipeline system. Pay-per-use with X402 micropayments on Base network.
import { withPaymentInterceptor } from 'x402-axios';
import axios from 'axios';
import { createWalletClient, http } from 'viem';
import { base } from 'viem/chains';
// Create wallet client
const walletClient = createWalletClient({
account: privateKeyToAccount(PRIVATE_KEY),
chain: base,
transport: http('https://mainnet.base.org')
});
// Apply X402 payment interceptor
const client = withPaymentInterceptor(
axios.create({ baseURL: 'https://x402-api.heyelsa.ai' }),
walletClient
);// Get portfolio (costs $0.01)
const portfolio = await client.post('/api/get_portfolio', {
wallet_address: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb7'
});
// Execute swap (costs $0.02)
const swap = await client.post('/api/execute_swap', {
from_chain: 'base',
from_token: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC
from_amount: '100',
to_chain: 'base',
to_token: '0x4200000000000000000000000000000000000006', // WETH
wallet_address: '0x...',
slippage: 2.0,
dry_run: false // Real execution
});https://x402-api.heyelsa.ai/api/endpoint_namehttps://x402-api.heyelsa.ai/api/elsa/endpoint_namehttps://x402-api.heyelsa.ai/api/hyperthon/endpoint_nameHYPERTHON is available for today only during the hackathon. Contact the Hyperthon organizers to obtain HYPERTHON tokens.
All three paths support the same endpoints with identical functionality. The only difference is the payment token used for X402 micropayments on Base network.
All execute endpoints use the Elsa pipeline for transaction orchestration. The pipeline handles approvals, swaps, and monitoring.
// 1. Execute swap
const result = await client.post('/api/execute_swap', {
from_chain: 'base',
from_token: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC
from_amount: '100',
to_chain: 'base',
to_token: '0x4200000000000000000000000000000000000006', // WETH
wallet_address: '0x...',
slippage: 2.0,
dry_run: false // Real execution
});
// 2. Monitor pipeline
const status = await client.post('/api/get_transaction_status', {
pipeline_id: result.data.result.pipeline_id
});
// 3. Sign when ready
if (status.data.status[0].status === 'sign_pending') {
const hash = await walletClient.sendTransaction(status.data.status[0].tx_data);
// 4. Submit transaction hash back to pipeline
await client.post('/api/submit_transaction_hash', {
task_id: status.data.status[0].task_id,
tx_hash: hash,
status: 'submitted'
});
}https://x402-api.heyelsa.ai/api/https://x402-api.heyelsa.ai/api/elsa/https://x402-api.heyelsa.ai/api/hyperthon/Available for today only during the hackathon. Contact the Hyperthon organizers to get HYPERTHON tokens.
All endpoints listed below work with all three base URLs. Simply change the path prefix to switch payment tokens.
Search for tokens across all blockchains
or /api/elsa/search_token
REQUEST
{
"symbol_or_address": "USDC",
"limit": 5
}RESPONSE
{
"success": true,
"result": {
"results": [
{
"symbol": "USDC",
"name": "USD Coin",
"address": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
"chain": "base",
"priceUSD": "1.000"
}
]
}
}Get real-time token price
REQUEST
{
"token_address": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
"chain": "base"
}Get wallet token balances
REQUEST
{
"wallet_address": "0x0D224DB2830A32bc75212A0ec6f0008C2B3ae5b5"
}RESPONSE
{
"balances": [
{
"asset": "USDC",
"balance": "1250.50",
"balance_usd": "1250.50",
"chain": "base"
}
]
}Comprehensive portfolio analysis
DESCRIPTION
Get a comprehensive view of wallet holdings including balances, DeFi positions, staking positions, and perpetual trading positions across Avantis and Hyperliquid.
REQUEST
{
"wallet_address": "0x0D224DB2830A32bc75212A0ec6f0008C2B3ae5b5"
}RESPONSE
{
"wallet_address": "0x0D224DB...",
"total_value_usd": "12345.67",
"chains": ["ethereum", "base", "arbitrum"],
"portfolio": {
"balances": [...],
"defi_positions": [...],
"staking_positions": [...],
"perpetual_positions": {
"avantis": [...],
"hyperliquid": [...]
}
}
}Wallet behavior and risk analysis
DESCRIPTION
Analyze wallet activity, behavior patterns, and risk profile including perpetual trading positions across Avantis and Hyperliquid.
REQUEST
{
"wallet_address": "0x0D224DB2830A32bc75212A0ec6f0008C2B3ae5b5"
}Profit and loss analysis
REQUEST
{
"wallet_address": "0x0D224DB2830A32bc75212A0ec6f0008C2B3ae5b5",
"time_period": "30_days"
}Get optimal swap routing and pricing
REQUEST
{
"from_chain": "base",
"from_token": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC
"from_amount": "100",
"to_chain": "base",
"to_token": "0x4200000000000000000000000000000000000006", // WETH
"wallet_address": "0x0D224DB2830A32bc75212A0ec6f0008C2B3ae5b5",
"slippage": 2.0
}RESPONSE
{
"quote": {
"from_amount": "100",
"estimatedOutput": "0.0283",
"price_impact": "0.12",
"gas_estimate": "0.45",
"route": ["USDC", "WETH"]
}
}Execute real blockchain swap
REQUEST
{
"from_chain": "base",
"from_token": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
"from_amount": "100",
"to_chain": "base",
"to_token": "0x4200000000000000000000000000000000000006",
"wallet_address": "0x0D224DB2830A32bc75212A0ec6f0008C2B3ae5b5",
"slippage": 2.0,
"dry_run": false
}RESPONSE (Pipeline Created)
{
"pipeline_id": "pip_123456789",
"tasks": [
{
"type": "approval",
"status": "sign_pending",
"tx_data": {
"to": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
"data": "0x095ea7b3...",
"value": "0x0"
}
},
{
"type": "swap",
"status": "pending"
}
]
}Create limit order via CoW Protocol
REQUEST
{
"from_chain": "ethereum",
"from_token": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"from_amount": "1000",
"to_token": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"limit_price": "0.0003",
"wallet_address": "0x0D224DB2830A32bc75212A0ec6f0008C2B3ae5b5",
"valid_for_hours": 24,
"dry_run": false
}View limit orders
REQUEST
{
"wallet_address": "0x0D224DB2830A32bc75212A0ec6f0008C2B3ae5b5"
}Cancel pending limit order
REQUEST
{
"order_id": "0x123...",
"wallet_address": "0x0D224DB2830A32bc75212A0ec6f0008C2B3ae5b5",
"dry_run": false
}List available perpetual trading pairs
DESCRIPTION
Get a list of available perpetual trading pairs across providers. Supports Avantis (Base, Arbitrum) and Hyperliquid.
REQUEST
{
"provider": "all"
}PARAMETERS
RESPONSE
{
"success": true,
"pairs": {
"avantis": [
{
"pair": "ETH-USD",
"chain": "base",
"max_leverage": 50
}
],
"hyperliquid": [
{
"pair": "BTC-USD",
"max_leverage": 50
}
]
}
}Query perpetual trading positions
DESCRIPTION
Get all open perpetual positions for a wallet across Avantis and Hyperliquid providers.
REQUEST
{
"wallet_address": "0x0D224DB2830A32bc75212A0ec6f0008C2B3ae5b5",
"provider": "all"
}PARAMETERS
RESPONSE
{
"success": true,
"positions": {
"avantis": [
{
"pair": "ETH-USD",
"size": "1.5",
"side": "long",
"leverage": 10,
"entry_price": "2500.00",
"pnl": "150.00"
}
],
"hyperliquid": []
}
}Get Hyperliquid market details for a specific token
DESCRIPTION
Get detailed market information for a specific perpetual contract on Hyperliquid, including funding rates and open interest.
REQUEST
{
"token": "ETH"
}PARAMETERS
RESPONSE
{
"success": true,
"details": {
"token": "ETH",
"mark_price": "2500.00",
"funding_rate": "0.0001",
"open_interest": "1000000",
"max_leverage": 50
}
}Open a new perpetual position
DESCRIPTION
Open a new long or short perpetual position on Avantis (Base, Arbitrum) or Hyperliquid. Supports stop loss and take profit parameters. User confirmation required for non-dry-run executions.
REQUEST
{
"provider": "avantis",
"chain": "base",
"pair": "ETH-USD",
"collateral_token": "USDC",
"collateral_amount": "1000",
"leverage": 10,
"side": "long",
"wallet_address": "0x0D224DB2830A32bc75212A0ec6f0008C2B3ae5b5",
"stop_loss": "2400",
"take_profit": "2600",
"dry_run": false
}PARAMETERS
RESPONSE (Pipeline Created)
{
"success": true,
"pipeline_id": "pip_perp_123456",
"tasks": [
{
"task_id": "task_abc123",
"action_type": "perp_open",
"status": "sign_pending",
"tx_data": {
"to": "0x...",
"data": "0x...",
"value": "0x0"
}
}
]
}Close a perpetual position
DESCRIPTION
Close a perpetual position fully or partially (1-100%). Supports both Avantis and Hyperliquid providers.
REQUEST
{
"provider": "avantis",
"chain": "base",
"pair": "ETH-USD",
"position_id": "pos_123",
"close_percentage": 100,
"wallet_address": "0x0D224DB2830A32bc75212A0ec6f0008C2B3ae5b5",
"dry_run": false
}PARAMETERS
RESPONSE (Pipeline Created)
{
"success": true,
"pipeline_id": "pip_perp_close_123",
"tasks": [
{
"task_id": "task_def456",
"action_type": "perp_close",
"status": "sign_pending",
"tx_data": {...}
}
]
}Modify position leverage or collateral (Avantis only)
DESCRIPTION
Modify the leverage or collateral of an existing perpetual position. Only available for Avantis provider on Base and Arbitrum.
REQUEST
{
"provider": "avantis",
"chain": "base",
"pair": "ETH-USD",
"position_id": "pos_123",
"new_leverage": 15,
"additional_collateral": "500",
"wallet_address": "0x0D224DB2830A32bc75212A0ec6f0008C2B3ae5b5",
"dry_run": false
}PARAMETERS
RESPONSE (Pipeline Created)
{
"success": true,
"pipeline_id": "pip_perp_modify_123",
"tasks": [
{
"task_id": "task_ghi789",
"action_type": "perp_modify",
"status": "sign_pending",
"tx_data": {...}
}
]
}Search Polymarket prediction markets by keyword
or /api/elsa/polymarket_search_markets
REQUEST
{
"search": "bitcoin"
}RESPONSE
{
"markets": [
{
"id": "0x1234...",
"question": "Will Bitcoin exceed $100k by end of 2025?",
"outcomes": ["Yes", "No"],
"prices": [0.62, 0.38],
"volume": "1250000",
"end_date": "2025-12-31"
}
]
}Get Polymarket account status, Safe wallet, balances, and allowances
or /api/elsa/polymarket_user_status
REQUEST
{
"wallet_address": "0x0D224DB2830A32bc75212A0ec6f0008C2B3ae5b5"
}Get user positions, trades, and open orders
or /api/elsa/polymarket_user_data
REQUEST
{
"wallet_address": "0x0D224DB2830A32bc75212A0ec6f0008C2B3ae5b5",
"include_open_positions": true,
"include_won_positions": true,
"include_orders": false, // requires encrypted_credentials
"include_trades": false,
"encrypted_credentials": "..." // optional, from polymarket_init_done
}Initialize Polymarket credential derivation — returns EIP-712 data for signing
or /api/elsa/polymarket_init
REQUEST
{
"wallet_address": "0x0D224DB2830A32bc75212A0ec6f0008C2B3ae5b5"
}RESPONSE
{
"typed_data": { ... }, // EIP-712 typed data to sign
"timestamp": 1700000000,
"nonce": 42
}Complete Polymarket init with signed EIP-712 — returns encrypted credentials
or /api/elsa/polymarket_init_done
REQUEST
{
"wallet_address": "0x0D224DB2830A32bc75212A0ec6f0008C2B3ae5b5",
"timestamp": 1700000000,
"nonce": 42,
"signature": "0xabc..." // signed EIP-712 typed data
}RESPONSE
{
"encrypted_credentials": "..." // pass to polymarket_user_data for order access
}Search Polymarket markets with date range filters
or /api/elsa/polymarket_advanced_search
REQUEST
{
"search": "election",
"limit": 20,
"start_date_min": "2026-01-01", // optional ISO date
"start_date_max": "2026-12-31", // optional
"end_date_min": "2026-06-01", // optional
"end_date_max": "2027-01-01" // optional
}Create a Polymarket order via pipeline (requires encrypted credentials)
or /api/elsa/create_polymarket_order
REQUEST
{
"wallet_address": "0x0D224DB2830A32bc75212A0ec6f0008C2B3ae5b5",
"market_id": "0x1234...",
"token_id": "123456789", // outcome token (Yes/No)
"side": "BUY", // "BUY" | "SELL"
"price": 0.62, // limit price 0.0–1.0
"size": 100, // share count
"neg_risk": false, // set true for neg-risk markets
"encrypted_credentials": "...", // from polymarket_init_done
"dry_run": false
}RESPONSE (Pipeline Created)
{
"pipeline_id": "pip_abc123",
"tasks": [ ... ] // monitor via get_transaction_status
}View staking positions
REQUEST
{
"wallet_address": "0x0D224DB2830A32bc75212A0ec6f0008C2B3ae5b5"
}RESPONSE
{
"total_staked_usd": "15250.75",
"stakes": [
{
"protocol": "Lido",
"token": "ETH",
"staked_amount": "5.0",
"apy": "4.2"
}
]
}Discover yield opportunities
REQUEST
{
"wallet_address": "0x0D224DB2830A32bc75212A0ec6f0008C2B3ae5b5"
}Airdrop Season 1 has ended. The endpoints below remain available for historical claim checks and any pending/unclaimed allocations from Season 1. Watch for Season 2 announcements.
Check airdrop eligibility and allocation
REQUEST
{
"chain": "base",
"tranche": 1,
"eoa_address": "0x0D224DB2830A32bc75212A0ec6f0008C2B3ae5b5"
}PARAMETERS
RESPONSE
{
"success": true,
"chain": "base",
"tranche": 1,
"eoa_address": "0x0D224DB2830A32bc75212A0ec6f0008C2B3ae5b5",
"airdrop_info": {
"chain": "base",
"from_address": "0x0D224DB2830A32bc75212A0ec6f0008C2B3ae5b5",
"amount": 1000.0,
"tranche": 1,
"status": "available"
},
"timestamp": "2025-01-19T12:00:00.000Z"
}airdrop_info.status values:
Claim ELSA airdrop tokens
DESCRIPTION
Creates a pipeline to claim your allocated ELSA tokens from a specific tranche. Use dry_run to preview the claim without executing. Once the pipeline is created, monitor with get_transaction_status and sign the transaction when status is "sign_pending".
REQUEST
{
"chain": "base",
"tranche": 1,
"eoa_address": "0x0D224DB2830A32bc75212A0ec6f0008C2B3ae5b5",
"dry_run": false
}PARAMETERS
RESPONSE (Pipeline Created)
{
"success": true,
"pipeline_id": "pip_abc123def456",
"chain": "base",
"tranche": 1,
"eoa_address": "0x0D224DB2830A32bc75212A0ec6f0008C2B3ae5b5",
"result": {
"pipeline_id": "pip_abc123def456",
"tasks": [
{
"task_id": "task_xyz789",
"action_type": "claim_elsa_airdrop",
"status": "sign_pending",
"tx_data": {
"to": "0x...",
"data": "0x...",
"value": "0x0"
}
}
]
},
"timestamp": "2025-01-19T12:00:00.000Z"
}The response includes a pipeline_id and result object containing tasks. Use the pipeline_id with /api/get_transaction_status to monitor progress and get tx_data for signing.
Get transaction history
REQUEST
{
"wallet_address": "0x0D224DB2830A32bc75212A0ec6f0008C2B3ae5b5",
"limit": 10
}Monitor pipeline status
REQUEST
{
"pipeline_id": "pip_123456789"
}RESPONSE
{
"pipeline_id": "pip_123456789",
"status": "in_progress",
"tasks": [
{
"task_id": "task_abc123",
"type": "approval",
"status": "success",
"tx_hash": "0xabc..."
},
{
"task_id": "task_def456",
"type": "swap",
"status": "sign_pending",
"tx_data": {...}
}
]
}Submit signed transaction hash to pipeline
DESCRIPTION
After signing a transaction with your wallet, submit the transaction hash back to the pipeline. This is required for multi-task pipelines (e.g., approval + swap) to track transaction status and continue with subsequent tasks.
REQUEST
{
"task_id": "task_def456",
"tx_hash": "0x1234567890abcdef...",
"status": "submitted"
}PARAMETERS
RESPONSE
{
"success": true,
"task_id": "task_def456",
"tx_hash": "0x1234567890abcdef...",
"status": "submitted"
}Submit EIP-712 typed data signature to pipeline
DESCRIPTION
After signing an EIP-712 typed data payload with your wallet, submit the signature back to the pipeline. Used by flows that require off-chain signatures (e.g., Polymarket order authorization, limit orders) to continue with subsequent tasks.
REQUEST
{
"task_id": "task_def456",
"signature": "0xabcdef1234...",
"status": "signed"
}PARAMETERS
RESPONSE
{
"success": true,
"task_id": "task_def456",
"signature": "0xabcdef1234...",
"status": "signed"
}Current gas prices
REQUEST
{
"chain": "base"
}Server health check
RESPONSE
{
"status": "healthy",
"service": {
"name": "Elsa X402 MCP Server",
"version": "1.0.0"
},
"payment": {
"protocol": "X402",
"network": "base",
"recipient": "0x0D224DB2830A32bc75212A0ec6f0008C2B3ae5b5"
}
}MCP integration will be available shortly
{
"mcpServers": {
"elsa-x402": {
"command": "node",
"args": ["/path/to/elsa-x402-mcp-server/build/index.js"],
"env": {
"X402_NETWORK": "base",
"X402_PAY_TO": "0x0D224DB2830A32bc75212A0ec6f0008C2B3ae5b5",
"CDP_API_KEY_ID": "your-cdp-key-id",
"CDP_API_KEY_SECRET": "your-cdp-key-secret"
}
}
}
}Learn more about the X402 protocol and related technologies powering this API.
The HTTP 402 Payment Required protocol enabling machine-to-machine micropayments.
CDP provides the wallet infrastructure for X402 payment processing.
The L2 blockchain where X402 payments are processed in USDC or ELSA.
Model Context Protocol for AI assistant integrations.
For issues or questions, reach out through our support channels