Batch Settlement

How Batch Settlement Works

Batch settlement is the economic foundation that makes micropayments (<$0.10 per API call) profitable on blockchain networks.

The Problem

Individual blockchain transactions are expensive relative to micropayments:

Without Batching:
API Call: $0.01
Gas Fee: $0.005 (per transaction)
Gas Overhead: 50% ❌

For 1,000 calls:
- Revenue: $10.00
- Gas Cost: $5.00 (1,000 transactions × $0.005)
- Net Profit: $5.00 (50% overhead - unprofitable!)

The Issue: Settling each payment individually consumes 5-50% of revenue in gas fees, making micropayments economically unviable.

The Solution

Preimage Research batches multiple payments into a single blockchain transaction:

With Batching:
API Calls: 100 payments × $0.01 = $1.00
Gas Fee: $0.005 (ONE transaction for all 100)
Gas per Payment: $0.00005
Gas Overhead: 0.5% ✅

For 1,000 calls (10 batches):
- Revenue: $10.00
- Gas Cost: $0.05 (10 batches × $0.005)
- Net Profit: $9.95 (0.5% overhead - profitable!)

The Result: 50-100x reduction in gas costs, enabling true micropayments.


How It Works

Step 1: Instant Payment Verification

When a user makes an API call:

1. User signs EIP-3009 payment authorization (client-side)
2. Gateway verifies signature cryptographically (5-10ms)
3. Service is granted immediately
4. Payment added to settlement queue

Users experience instant access - no waiting for blockchain confirmation.

Step 2: Payment Accumulation

Payments are queued per wallet address:

settlement_queue:
  wallet_address: "0xABC..."
  accumulated_usdc: $0.50
  payment_count: 50
  pending_signatures: [sig1, sig2, ..., sig50]
  first_payment_at: 2024-01-15 10:00:00

Step 3: Automatic Settlement Triggers

The system checks every 60 seconds if any queue meets settlement criteria:

TriggerThresholdPurpose
Amount$1.00Ensures gas overhead ≤1%
Count100 paymentsOptimizes for high-frequency users
Time1 hourGuarantees no payment waits indefinitely
High-Value$10+Immediate settlement for large payments

When ANY trigger condition is met, the batch settles automatically.

Step 4: Blockchain Settlement

All pending payments are submitted in one transaction via a multicall smart contract:

// USDCBatchSettlement.sol
function batchTransferWithAuth(
    address[] calldata froms,      // Buyers
    address[] calldata tos,        // Providers
    uint256[] calldata values,     // Amounts
    // ... EIP-3009 signatures
) external {
    for (uint i = 0; i < froms.length; i++) {
        usdc.transferWithAuthorization(...);
    }
}

Result: 100 payments → 1 blockchain transaction → Gas cost divided by 100.


Economic Impact

Cost Breakdown by Payment Size

Payment SizeBatch SizeGas/BatchGas/PaymentGas OverheadNet/Payment
$0.0011000$0.005$0.0000050.5%$0.0010
$0.01100$0.005$0.000050.5%$0.0100
$0.1020$0.005$0.000250.25%$0.0998
$1.0010$0.005$0.00050.05%$0.9995
💡

Key Insight: Batching enables profitable micropayments down to $0.001 per API call.

Minimum Viable Payment Comparison

SystemMin Viable PaymentGas OverheadUse Cases
Without Batching$0.105%Limited APIs
With Batching$0.0010.5%AI agents, micropayments, high-frequency

Real-World Scenarios

Scenario 1: Low-Frequency Blogger API

Traffic: 5 API calls per hour
Price: $0.10 per call

Timeline:
00:00 - Call #1: $0.10 → Queue
00:15 - Call #2: $0.10 → Queue ($0.20 total)
00:45 - Call #3: $0.10 → Queue ($0.30 total)
01:00 - ⚡ TIME TRIGGER (1 hour)
      → Batch settles 3 payments in 1 transaction

Economics:
- Revenue: $0.30
- Gas: $0.005
- Overhead: 1.7%
- Net: $0.295

Trigger: Time (ensures hourly settlement for low-frequency users)

Scenario 2: Medium-Frequency Image API

Traffic: 30 API calls per hour
Price: $0.05 per call

Timeline:
10:00 - Start
10:35 - After 21 calls: $1.05 accumulated
      ⚡ AMOUNT TRIGGER ($1.00 threshold)
      → Batch settles 21 payments in 1 transaction

Economics:
- Revenue: $1.05
- Gas: $0.01
- Overhead: 0.95%
- Net: $1.04

Trigger: Amount (balances settlement frequency with efficiency)

Scenario 3: High-Frequency AI Agent API

Traffic: 1,000+ API calls per hour
Price: $0.01 per call

Timeline:
14:00 - 100 calls in 6 minutes: $1.00
      ⚡ COUNT TRIGGER (100 payments)
      → Batch settles immediately
14:06 - Another 100 calls → Another batch
14:12 - Another 100 calls → Another batch
...continues throughout the hour...

Economics per batch:
- Revenue: $1.00
- Gas: $0.01
- Overhead: 1.0%
- Net per call: $0.0099
- Hourly: ~10 batches = $9.90 net revenue

Trigger: Count (optimizes for high throughput)

Scenario 4: Enterprise Data API

Traffic: 10 API calls per hour
Price: $15.00 per call

Timeline:
09:00 - First call: $15.00
      ⚡ HIGH-VALUE TRIGGER (`$10+` threshold)
      → Immediate individual settlement
      (Gas is 0.03% - worth settling right away)

Economics:
- Revenue: $15.00
- Gas: $0.005
- Overhead: 0.03%
- Net: $14.995

Trigger: High-value (immediate settlement for large payments)


Comparison Summary

ScenarioFrequencyPrice/CallTriggerBatch SizeGas OverheadNet/Call
Blogger5/hour$0.10Time (1h)3-51.7%$0.098
Image API30/hour$0.05Amount ($1)20-251.0%$0.0495
AI Agent1000/hour$0.01Count (100)1001.0%$0.0099
Enterprise10/hour$15.00High-value10.03%$14.995

Key Takeaways

Universal Coverage: All usage patterns are optimized automatically
Predictable Economics: Gas overhead typically 0.5-1.7%
No Configuration: Triggers adapt to your usage pattern
Cash Flow: No payment waits longer than 1 hour
Micropayments Viable: Profitable down to $0.001 per call

The Bottom Line: Batch settlement makes micropayment APIs economically viable. The system automatically optimizes based on your traffic pattern - no configuration required.


Next Steps