
Sluice
Pay-per-call API gateway monetizing AI inference in native USDC settled on Arc.
Demo
About
Project Overview: Sluice — Pay-Per-Call API Monetization on Arc Sluice is an autonomous, machine-native pay-per-call API gateway that monetizes digital services and AI inference in native USDC settled instantly on Arc Layer 1. It bridges the critical gap between traditional web APIs and autonomous AI agents by replacing human-dependent SaaS subscriptions with standard HTTP 402 Payment Required challenges and an immutable on-chain UsageVault smart contract. The Problem Today, API monetization is fundamentally broken for autonomous machines: Subscriptions Fail Autonomous Agents: AI agents operate per task or per second. They cannot create accounts, complete KYC, sign monthly subscription contracts, or manage credit card portals. Credit Card Rails are Too Slow & Expensive: Traditional card rails charge $0.30 + 2.9% per transaction and settle in 2–3 business days, making micro-transactions (e.g., $0.05 per AI inference call) economically impossible. Private Database Lock-In: Traditional metered API billing records usage inside private off-chain databases (AWS RDS, Stripe logs). Neither the buyer, the autonomous agent, nor independent third-party auditors can verify whether the billing was accurate, transparent, or manipulated. How Sluice Solves This Sluice provides a trust-minimized, machine-speed monetization layer where payment, execution, and accounting happen autonomously in a single closed loop: Standard HTTP 402 Challenge: When an unpaid human or AI agent sends an API request (e.g., to an AI inference endpoint), the Sluice Gateway intercepts the call and immediately returns a standard HTTP 402 Payment Required response with structured JSON containing the price (0.05 USDC), the network (Arc Testnet #5042002), and the target UsageVault contract address. Sub-Second Native USDC Settlement: The caller transmits a micro-payment transaction on Arc. Because Arc uses native USDC for both transaction value and network gas, agents do not need secondary gas tokens or complex automated swaps. On-Chain Accounting via UsageVault.sol: The payment triggers recordPayment() on a custom Solidity smart contract on Arc. The contract isolates seller balances, enforces Checks-Effects-Interactions (CEI) against reentrancy, and emits an immutable UsageRecorded event log. Autonomous AI Inference Unlocking: The gateway validates the transaction receipt directly on Arc L1. Once verified, the gateway unlocks the protected microservice (powered by live Google Gemini 3.6 Flash neural models) and delivers the result along with verifiable on-chain transaction proof. Key Technical Innovations Zero Private Database Dependency: The Arc blockchain is the canonical database. If the API seller's servers go down, their revenue accounting, usage receipts, and withdrawable treasury remain completely intact and provable on-chain. Customizable Withdrawal Thresholds: To prevent micro-dust fragmentation and optimize gas efficiency, sellers configure custom payout thresholds (e.g., minimum $0.50 USDC) before executing non-custodial batch withdrawals. Meridian Neumorphic Mission Control: A high-precision tactile dashboard featuring real-time Arc L1 block telemetry, RPC latency ping tracking (~40ms), an interactive 402 visualizer aperture, 1-click prompt presets, and an on-chain audit ledger. 100% Real On-Chain Execution: Zero mocked data. The system is deployed live on Arc Testnet at contract address 0x2fB757b6158320b239a6eC4f7d7A0149D858D890 and is completely scripted for immediate Arc Mainnet deployment.
How it's made
How It's Made: Technical Architecture & Implementation Details 1. Technologies Used Blockchain & Settlement: Arc Testnet (Chain ID 5042002), Solidity 0.8.20, Hardhat, Foundry, Ethers.js v6. Partner / Core Network Technology: Arc Layer 1 Network (Native USDC as the gas and execution token, Arcscan Block Explorer). AI & Machine Intelligence: Google Gemini 3.6 Flash neural inference engine. Backend & Gateway Layer: Next.js 14 App Router (Node.js runtime serverless API routes, HTTP 402 middleware specification). Frontend Architecture: React 18, HTML5 2D Canvas for procedural kinetic shaders, Canvas-Confetti, Lucide Icons. Design & Material System: Meridian Neumorphic Design System v2.0 (Monochrome dark neumorphism, dual-directional tactile lighting, tri-font hierarchy: Fraunces serif for editorial numbers, Space Grotesk for technical controls, and IBM Plex Mono for the ledger). 2. How the Components Are Pieced Together The Smart Contract Layer (UsageVault.sol): We wrote a non-custodial smart contract deployed on Arc Testnet at 0x2fB757b6158320b239a6eC4f7d7A0149D858D890. The contract implements isolated balance mappings per seller, enforces strict Checks-Effects-Interactions (CEI) reentrancy protection (zeroing state balances before external calls), and allows sellers to set automated withdrawal thresholds to batch transactions and eliminate micro-dust gas waste. The HTTP 402 Payment Interceptor (/api/gate/summarize): Inbound requests hit the gateway. If no X-402-Payment-Proof header is attached, the route immediately halts and returns an RFC-compliant HTTP 402 Payment Required challenge alongside a WWW-Authenticate header containing the price (0.05 USDC), chain ID (5042002), and vault address. On-Chain Settlement Verification & AI Execution: When the caller submits their transaction hash, the gateway queries the Arc Testnet RPC directly via provider.getTransactionReceipt(hash) and parses the UsageRecorded event emitted by UsageVault.sol. Only upon confirmed Arc L1 finality does the gateway forward the prompt to live Google Gemini 3.6 Flash, returning the inference payload, condense ratios, semantic insights, and a clickable Arcscan verification link. 3. How Arc Network Uniquely Benefited the Project Building on Arc was essential for making this project possible: Native USDC as Gas: On other chains, an AI agent needs two separate tokens: USDC for the API service and ETH/MATIC for network gas. On Arc, native USDC is the gas token. An agent only holds a single balance of native USDC, making automated, friction-free micro-payments possible. Sub-Second Block Finality: AI agents cannot afford to wait 12–15 seconds for a block confirmation. Arc's sub-second block times allow the 402 payment and AI unlock loop to complete in near real time. 4. Notable Engineering & "Hacky" Solutions Zero-Database Event Sourcing: We completely eliminated off-chain databases (no MongoDB, Postgres, or Redis). The seller treasury, historical call receipts, and audit trail are reconstructed dynamically on the client by querying event logs (UsageRecorded) directly from the Arc L1 contract. The blockchain is our canonical database. Forced EIP-2255 Account Re-Selection: Web3 wallets like MetaMask normally cache connected accounts and silently reconnect without prompting. We implemented a cache-clearing routine using wallet_requestPermissions with { eth_accounts: {} } before calling eth_requestAccounts, forcing MetaMask to pop up the account picker on every single connect click so users can switch wallets effortlessly. Deterministic Number Formatting across Server & Client: In Next.js SSR, system locale differences (e.g., Indian comma grouping 6,12,45,980 on the server vs US standard 61,245,980 on the browser) trigger React hydration mismatches. We implemented a deterministic regex formatter with suppressHydrationWarning to ensure byte-for-byte identical HTML across all locales. Procedural 60 FPS Canvas Kinetic Wallpapers: Rather than using static CSS or heavy video backgrounds, we engineered a canvas engine (LiveWallpaperEngine.tsx) with 3 interactive mathematical shaders: Hydro (laminar wave deflection), Quantum (3D undulating mesh), and Celestial (gravitational orbit physics), responding in real time to pointer coordinates.