middlebit

x402 payment middleware for stablecoin content gating on Base.

loading...

Middlebit normalizes USDC (EIP-3009) and SBC (EIP-2612) payments into a consistent API. Point your frontend at middlebit with your merchant wallet address — everything else (facilitator setup, signature standards, on-chain settlement) is handled for you.

What You Need

  1. Middlebit URL:
  2. Your merchant wallet address (where you receive funds)

That's it. No API keys, no extra accounts, no backend configuration.

Supported Tokens

TokenStandardDecimalsAddress
USDC EIP-3009 6 0x833589fC...02913
SBC EIP-2612 18 0xfdcC3dd6...80798

Both on Base (chain ID 8453). The user pays zero gas — middlebit settles on-chain.

API Endpoints

GET /api/health

Health check. Returns version and supported tokens.

GET /api/supported-tokens

Token configs for client discovery.

POST /api/payment-requirements

Returns 402 with x402 v1 payment requirements. The frontend uses these to construct the EIP-712 signing request.

Note: You pass your merchant wallet as payTo. The response returns the on-chain addresses middlebit uses internally — your client just needs to sign what's returned.

POST /api/settle

Settles a signed payment on-chain. The paymentSignature is a base64-encoded x402 v1 payload.

Funds Flow

Dashed lines are data/instructions. Solid lines are value transfers. Follows the Commons Stablecoin Format.

CSF v1.4.5 · Medium
sequenceDiagram
    participant User as End User Wallet
    participant Plugin as Frontend / Plugin
    participant Middlebit as middlebit
    participant Base as Base Blockchain
    participant Merchant as Merchant Wallet

    User-->>Plugin: [DATA] Request gated content
    Plugin-->>Middlebit: [DATA] POST /api/payment-requirements
    Middlebit-->>Plugin: [DATA] 402 Payment Required
    Plugin-->>User: [DATA] EIP-712 signing request
    User->>Plugin: Sign USDC Base 0.25
    Plugin-->>Middlebit: [DATA] POST /api/settle (signed payload)
    Middlebit->>Base: Transfer USDC Base 0.25
    Base->>Merchant: Confirm Receipt
    Middlebit-->>Plugin: [DATA] Transaction receipt
    Plugin-->>User: [DATA] Content unlocked
      

The end user pays zero gas. When a user pays, they sign a transfer to a settlement wallet configured to support the transfer flow. Middlebit submits it for on-chain execution, and funds are forwarded to your merchant wallet. You provide your merchant wallet address, token choice, amount, and resource URL.

Integration Prompt

Copy this and hand it to an AI coding agent or use it as a spec to build a client:


    

Source

Middlebit is open source. The codebase is ~500 lines of TypeScript across 4 API endpoints and 3 utility modules.