Payment Flow (x402)

BonzAI uses an HTTP 402-inspired payment protocol for P2P inference. Payments are processed on Base (chain ID 8453) in ETH or USDC.

Protocol Overview

The x402 flow follows a challenge-response pattern:

  1. Consumer sends inference request to provider via libp2p

  2. Provider returns 402 Payment Required with amount and address

  3. Consumer sends payment (ETH or signed EIP-712 authorization)

  4. Consumer retries request with payment proof (tx hash)

  5. Provider verifies payment on-chain, processes inference, returns result

Payment Methods

Direct ETH Payment

The simplest flow — consumer sends ETH directly:

Consumer → BonzaiPayment.payDirectETH(provider, service) + msg.value

Direct USDC Payment

Consumer approves and sends USDC:

Pre-Deposited Balance

For faster payments, consumers can pre-deposit funds:

EIP-712 Signed Authorization

For contract-mediated payments with replay protection:

  1. Consumer signs an EIP-712 typed message:

  2. Provider submits the signature to BonzaiPayment.processPayment()

  3. Contract verifies signature, deducts from consumer's deposited balance, distributes funds

Domain: BonzAI x402 version 2, chain ID 8453

Fee Split

On every payment:

Recipient
Share

Provider

97.5%

Treasury

2.5%

Pricing

Providers set a pricePerToken (price per 1,000 tokens in wei) during registration.

The consumer's cost is calculated as:

Minimum: 100 tokens per request.

Self-Inference

If the consumer and provider are the same node (matching peerId), no payment is required. Self-inference is always free.

Replay Protection

  • On-chain: Each (consumer, nonce) pair can only be used once

  • Off-chain: Provider maintains a nonce cache in Electron Store (24h TTL, 10K entry cap)

  • Expiry: Signed payments expire after 5 minutes

Supported Tokens

Token
Enum Value
Decimals

ETH

0

18

USDC

1

6

USDC on Base: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913arrow-up-right

Last updated