A pipe for money. Stream funds into an escrow buffer. Consuming processes drain it in real-time.
That's it. Simple as Unix pipes, but for payments.
# Money flows in → escrow buffer → consuming process drains it → auto-refund remainder
pipe402 stream api.com/data --deposit 0.01Traditional payments: Pay upfront, hope you get what you paid for.
pipe402: Money flows through a pipe into an escrow buffer. The consuming process (API, service, stream) drains funds as it delivers value. When you're done, remaining funds flow back to you automatically.
[Your Wallet] → [pipe402] → [Escrow Buffer] → [Consuming Process]
$0.01 ↓ $0.01 drains $0.00001/byte
↓ ↓
↓ [Remaining: $0.007]
↓ ↓
← ← ← ← ← [Auto-refund] ← ← ←
No subscriptions. No pre-loading balances. No trust required.
- Open pipe → Deposit funds to smart contract escrow
- Stream data → Service drains funds per unit consumed (bytes, tokens, seconds, etc.)
- Close pipe → Auto-refund remaining balance
The escrow contract sits between you and the service. Neither party can cheat.
# Stream a webpage, pay per byte
pipe402 stream google.com --deposit 0.01# Service defines pricing: $0.01 per token
pipe402 stream ai-service.com/chat?prompt="Hello" --deposit 0.50
# Automatically detects: "tokens at $0.01 per token"
# Consumes exactly what the AI uses, refunds the rest# Audio streaming: $0.001 per second
pipe402 stream audio.com/stream --deposit 0.10
# Automatically detects: "seconds at $0.001 per second"
# Pay for exactly how long you listen# API service: $0.05 per request
pipe402 stream data-api.com/query --deposit 0.20
# Automatically detects: "requests at $0.05 per request"
# Pay per API call, not monthly subscriptionServices define their own pricing by adding HTTP headers:
HTTP/1.1 200 OK
x402-unit-type: tokens
x402-unit-price: 0.01
x402-units-consumed: 150That's it. Any service can become pipe402-compatible by adding three headers. No SDK, no registration, no complexity.
Supported unit types:
bytes- Raw data (default)tokens- AI/LLM tokensseconds- Time-based consumptionrequests- API callsframes- Video framesanything- Providers can define custom units
# Clone and build
git clone https://github.com/boorich/pipe402
cd pipe402
./scripts/init.sh
cargo build --release --features ethers
# Install globally (optional)
sudo cp target/release/pipe402 /usr/local/bin/
# Setup wallet and get testnet funds (guided wizard)
pipe402 setupThe setup wizard will:
- 🔑 Generate a new wallet for you
- 💰 Guide you to get free Base Sepolia ETH from faucets
- ✅ Verify your balance before proceeding
- 🚀 Test your first micropayment stream
No crypto knowledge required! The wizard handles everything.
Need more funds later? Just run pipe402 fund for faucet links.
Base Sepolia Testnet (Default):
- Factory:
0x0Da237b3aDb95214a3a95f934990959AE710bbb7(pre-configured) - Creates minimal proxy escrow contracts per consumer+provider pair
- Trustless: Neither party can steal funds
- Automatic refunds when pipe closes
Works out of the box - no configuration needed for testing!
Deploy your own:
cd contracts
forge build
forge create PipeEscrow --rpc-url [YOUR_RPC] --private-key [YOUR_KEY]
forge create PipeFactory --constructor-args [ESCROW_ADDRESS] --rpc-url [YOUR_RPC] --private-key [YOUR_KEY]Try different pricing models with the included test server:
# Start test provider
python3 examples/x402-provider.py
# Test token-based pricing
pipe402 stream "localhost:8402/tokens?prompt=Hello" --deposit 0.10
# Test time-based pricing
pipe402 stream "localhost:8402/seconds?duration=5" --deposit 0.05
# Test request-based pricing
pipe402 stream localhost:8402/requests --deposit 0.10Rust CLI (src/) - Handles streaming, escrow interaction, consumption tracking
Smart Contracts (contracts/) - Trustless escrow and factory for creating pipes
x402 Protocol - HTTP headers for provider-defined pricing
Key insight: The escrow contract is the "pipe buffer" - money flows in, gets consumed in real-time, remainder flows back out.
- AI Services - Pay per token, not monthly subscriptions
- Data APIs - Pay per request, not flat fees
- Media Streaming - Pay per second/frame, not bundles
- Compute Services - Pay per CPU cycle, not reserved instances
- Any metered service - Fair pricing based on actual consumption
Current internet: Pay upfront, hope for the best, fight for refunds.
pipe402 internet: Money flows like data. Pay for exactly what you consume. Automatic settlement. No trust required.
It's not just micropayments - it's a new economic model for the internet.
License: MIT
Network: Base Sepolia (testnet)
Status: Working prototype - real micropayments flowing through smart contracts