Skip to content

boorich/pipe402

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pipe402

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.01

The Concept

Traditional 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.

How It Works

  1. Open pipe → Deposit funds to smart contract escrow
  2. Stream data → Service drains funds per unit consumed (bytes, tokens, seconds, etc.)
  3. Close pipe → Auto-refund remaining balance

The escrow contract sits between you and the service. Neither party can cheat.

Examples

Basic Web Streaming

# Stream a webpage, pay per byte
pipe402 stream google.com --deposit 0.01

AI Token Consumption

# 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

Time-based Services

# 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 Calls

# 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 subscription

Provider Integration

Services 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: 150

That'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 tokens
  • seconds - Time-based consumption
  • requests - API calls
  • frames - Video frames
  • anything - Providers can define custom units

Setup

# 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 setup

The setup wizard will:

  1. 🔑 Generate a new wallet for you
  2. 💰 Guide you to get free Base Sepolia ETH from faucets
  3. ✅ Verify your balance before proceeding
  4. 🚀 Test your first micropayment stream

No crypto knowledge required! The wizard handles everything.

Need more funds later? Just run pipe402 fund for faucet links.

Smart Contracts

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]

Test Provider

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.10

Architecture

Rust 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.

Use Cases

  • 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

Why This Matters

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

About

Pipe money like data

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published