
L402-over-eth-Layer2
L402-EL2 is an author's proposal and open-source implementation that adapts the Lightning-based L402 HTTP 402 payment pattern to Ethereum L2s, replacing invoices/preimages with a prefunded escrow contract and cumulative EIP-712 vouchers signed per call. It layers macaroons with caveats (tool, max_cumulative, expires_at) for HTTP credentials and attenuation to sub-agents, on-chain session keys with spending caps (ERC-1271/ERC-4337 compatible), and batch settlement, so an agent pays a provider per MCP tool call without a transaction per call. The stated design specifically meters MCP's tools/call, resources/read, and prompts/get while leaving initialize/tools/list free for discovery, aimed at agent orchestrators calling paid LLM APIs like the author's own LightPhon service; contracts are unaudited.
What it claims
L402-EL2 keeps the L402 wire format, so existing L402 parsers still work, and replaces Lightning invoices with a unidirectional payment channel on an Ethereum L2. The author's stated results:
- On-chain cost: each channel lifecycle needs 2 on-chain transactions (open and settle), not one per call.
- Latency: payment adds under 10 ms per request. Paying on-chain per call would add about 1–2 s and cost more in gas than the service.
- Token: any ERC-20 works. The author uses wrapped BTC (cbBTC, WBTC, tBTC) so prices match their Lightning side.
How it works
- Channel ID:
channelId = keccak256(abi.encode(payer, provider, token)). Either side can compute it offline before the channel exists. - Voucher: each call signs
Voucher(channelId, cumulativeAmount, nonce, validUntil)with EIP-712. The amount is a running total, which has three effects: - old vouchers cannot be replayed;
- the server stores one row per channel;
- verification is an in-memory signature check of about a millisecond, with no RPC call.
- Session keys:
authorizeSigner(key, maxCumulative, validUntil)puts the spending cap in the contract rather than the client. - 24h challenge period: revoking or tightening a session key waits the same 24h as a channel close. This stops a payer from voiding vouchers the provider has already served.
- Deposits: besides normal deposits, single-signature deposits via ERC-2612 and ERC-3009 are supported.
- Settlement: a separate settler submits the latest voucher for many channels in one
settleBatch()call.
sequenceDiagram
participant A as Agent
participant P as Provider
participant C as L402Escrow (L2)
A->>C: open prefunded channel (tx 1)
loop per paid MCP call
A->>P: request
P-->>A: 402 challenge
A->>P: retry + macaroon + cumulative voucher
P->>P: in-memory sig check
end
P->>C: settleBatch latest vouchers (tx 2)How to use it
The page says the repo contains:
- the
L402Escrow.solcontract, with node and Foundry tests, including fuzzing; - TypeScript server, client and settler packages;
- a protocol spec;
- an end-to-end example that runs on an in-process EVM with no configuration.
The page gives no install commands or licence. The project site is https://www.l402-over-eth-l2.com/.
Limits
- Not audited. The author says not to use it with real funds yet.
- Early-stage feedback request. The author describes themselves as less expert in payment channels, EIP-712 and account abstraction than the forum audience, and says they wrote it with LLM help.
- Funds lock-up. Closing a channel and revoking a session key both wait 24h, so neither takes effect immediately.
- Conflict of interest. The author is LightPhon's founder and plans to use the system there.
- No independent measurements. The <10 ms and ~ms verification figures are the author's claims. The page gives no benchmark setup.
Organisations named here
- LightPhon
- Ethereum Magicians
- ERC-1271
- ERC-2612
- ERC-3009
- ERC-4337
Technologies named here
- L402
- L402-EL2
- L402Escrow.sol
- Foundry
- Model Context Protocol
- TypeScript
- EIP-712
- Lightning Network
- Solidity
Techniques named here
- Cumulative EIP-712 vouchers
- Macaroons for HTTP credentials
- On-chain session keys
- Batch settlement
Related in ai-infra
kerpopule/hermes-jev-skills
Wire It, Run It, Deploy It: AI Workflows in Gradio
