Skip to content

meraj97/inferpay

Repository files navigation

⚡ InferPay — Pay-per-Inference AI Agent on Arc (Ollama Edition)

Hackathon: Stablecoin Commerce Stack Challenge — Track 4: Agentic Economy Free local AI (Ollama + Llama 3) · Circle USDC · Arc L1 Testnet


What is InferPay?

An AI agent that charges $0.01 USDC per query, deducted from a Circle wallet and settled on the Arc blockchain in real time. The AI runs completely free and locally via Ollama — no OpenAI or Anthropic account needed.


Quick Start (3 steps)

1. Install Ollama + pull model

# Install Ollama: https://ollama.com/download
# Then:
ollama serve           # start Ollama (keep this running)
ollama pull llama3     # download Llama 3 (~4GB, one-time)

2. Install & configure the app

git clone https://github.com/yourusername/inferpay
cd inferpay
npm install
cp .env.example .env.local
# Fill in CIRCLE_API_KEY, AGENT_WALLET_ID, AGENT_WALLET_ADDRESS

3. Run

npm run dev
# Open http://localhost:3000

That's it. No AI API key needed.


Architecture

User → Next.js Frontend
     → POST /api/infer
       → Circle Wallets (charge $0.01 USDC on Arc)
       → InferPayAgent.sol (record payment on-chain)
       → Ollama local API (run Llama 3 inference — FREE)
     → Response + tx receipt → UI

Environment Variables

Variable Required Description
CIRCLE_API_KEY From console.circle.com
CIRCLE_BASE_URL https://api-sandbox.circle.com
CIRCLE_WALLET_SET_ID From Circle console
AGENT_WALLET_ID Treasury wallet ID
AGENT_WALLET_ADDRESS Treasury wallet address
OLLAMA_BASE_URL optional Default: http://localhost:11434
OLLAMA_MODEL optional Default: llama3
COST_PER_INFERENCE_USDC optional Default: 0.01

Supported Ollama Models

Any model you pull with ollama pull <name> works. Recommended:

Model Size Speed Quality
llama3 4.7GB Fast Great
llama3:8b 4.7GB Fast Great
llama3:70b 40GB Slow Excellent
mistral 4.1GB Fast Good
phi3 2.3GB Very fast Good

Change model in .env.local: OLLAMA_MODEL=mistral


Circle Products Used

  • USDC — primary payment rail for per-inference charges
  • Circle Wallets — developer-controlled wallets on Arc
  • Circle Gateway — treasury routing
  • Nanopayments — sub-cent high-frequency payment pattern

Project Structure

inferpay/
├── app/
│   ├── api/
│   │   ├── infer/route.js         ← paid inference endpoint
│   │   ├── wallet/route.js        ← wallet create/balance
│   │   ├── transactions/route.js  ← tx history
│   │   └── health/route.js        ← Ollama health check
│   ├── dashboard/page.jsx         ← full UI with Ollama status
│   └── layout.jsx / page.jsx
├── lib/
│   ├── agent.js                   ← orchestrates payment + Ollama
│   ├── ollama.js                  ← Ollama API client
│   └── circle.js                  ← Circle API client
├── contracts/
│   └── InferPayAgent.sol          ← Arc smart contract
└── scripts/deploy.js

Deploy Smart Contract on Arc

# Add to .env.local:
# DEPLOYER_PRIVATE_KEY=...
# ARC_USDC_ADDRESS=...

npm install --save-dev @nomicfoundation/hardhat-toolbox
npx hardhat run scripts/deploy.js --network arc_testnet

Circle Product Feedback

Why we chose these products

  • Circle Wallets on Arc — dollar-denominated gas makes $0.01 micropayments viable. ETH gas volatility would make sub-cent pricing unpredictable.
  • USDC — stable, predictable unit of account for metered AI billing.
  • Nanopayments pattern — exactly right for agentic pay-per-use workloads.

What worked well

  • Sandbox faucet (/v1/faucet/drips) made testnet onboarding instant
  • Arc's predictable fees are a genuine DX improvement over EVM chains
  • Developer-controlled wallets abstract key management complexity

What could be improved

  • Native webhooks for transfer state changes would reduce polling
  • Clearer docs on Arc testnet USDC contract addresses
  • A Circle CLI (like Stripe CLI) for local webhook forwarding

Recommendations

  • Gas abstraction / sponsored transactions for USDC transfers
  • A dedicated "agent wallet" tier with built-in rate limits and spending caps

License

MIT — built for the Stablecoin Commerce Stack Challenge hackathon.

About

Pay-per-inference AI agent on Arc using Circle USDC

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors