The economics of batching
Settling a USDC transfer onchain costs gas. Even on low-fee blockchains, gas costs can exceed the value of a sub-cent payment. Batching solves this by amortizing gas across thousands of payments:| Approach | Gas cost per payment | Viable minimum payment |
|---|---|---|
| Individual settlement | Full gas per transaction | ~$0.01+ (depends on blockchain) |
| Batched settlement | Gas / number of payments in batch | $0.000001 |
Payment lifecycle
A nanopayment moves through five stages from initiation to settlement:Deposit
The buyer deposits USDC from their wallet into a Gateway Wallet contract.
This is a one-time onchain transaction that establishes the buyer’s Gateway
balance. Once deposited, the buyer can make gasless payments from this
balance.
Request and negotiate
The buyer requests a paid resource. The seller responds with
402 Payment Required, including payment details. This follows the standard x402
protocol flow.Sign authorization
The buyer signs an EIP-3009
TransferWithAuthorization message authorizing Gateway to transfer USDC
from their balance to the seller. This signature is created offchain and
costs zero gas. The buyer retries the request with the signed authorization
attached.Settle and serve
The seller (or a facilitator) submits the signed authorization to Gateway.
Gateway verifies the signature, locks the buyer’s funds, and credits the
seller’s pending balance. The seller serves the resource immediately,
without waiting for onchain settlement. Neither the buyer nor the seller
pays gas for this step.
Batch and onchain settlement
Gateway periodically collects pending authorizations, computes net balance
changes across all participants, and submits a single onchain transaction
that applies the changes. After onchain confirmation, pending balances
become available. The seller can then withdraw funds to any supported
blockchain.
Security model
Gateway’s batching system is non-custodial. Gateway never has arbitrary control over user funds. The security model relies on three components:Trusted execution environment (TEE)
A Trusted Execution Environment (TEE) is an isolated hardware enclave that runs code in a secure, tamper-proof environment. Gateway uses an AWS Nitro Enclave to:- Verify every EIP-3009 signature before including it in a batch
- Compute net balance changes across all payments in the batch
- Sign the batch result with the enclave’s private key
Onchain verification
The Gateway Wallet smart contract verifies the TEE’s signature before executing any batch. If the signature is invalid or comes from an unauthorized signer, the contract reverts. This ensures that only correctly computed batches are applied onchain.Cryptographic attestations
AWS Nitro Enclaves produce cryptographic attestation documents that prove the enclave is running a specific, audited code image. These attestations can be independently verified, providing transparency into the batching process.Balance states
Gateway tracks funds through multiple states as they move through the batching pipeline:| State | Description |
|---|---|
available | Spendable balance. Set after deposit or after receiving a settled batch payment. |
Example: Alice sends 10 USDC to Bob
| Event | Alice (sender) | Bob (receiver) |
|---|---|---|
| Initial state | available: 100 | available: 0 |
| Authorization submitted | available: 90 | available: 0 |
| Batch settled onchain | available: 90 | available: 10 |