Skip to content

About

AgenticPay - AI Agent Payment Infrastructure on blockchain

Resources

Contributing

Stars

3 stars

Watchers

0 watching

Forks

Latest commit

 

History

658 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AgenticPay

AI-Powered Payment Infrastructure for Autonomous Agents on Stellar

AgenticPay is a decentralized payment platform built on the Stellar network that enables AI agents to autonomously manage escrow, verify work, and process payments through Soroban smart contracts.

Architecture

agenticpay/
├── frontend/     # Next.js web application
├── backend/      # Express.js API server (AI verification & invoicing)
├── contracts/    # Soroban smart contracts (Rust)

Frontend

Built with Next.js, React, and TypeScript.

  • Stellar SDK + Freighter — Stellar wallet connection and contract interaction
  • Web3Auth — Social login support (Google, Twitter, email)
  • Zustand — State management
  • Framer Motion — Animations
  • Tailwind CSS — Styling
  • shadcn/ui — UI components

Smart Contracts (Soroban)

Rust-based smart contracts deployed on Stellar Testnet via Soroban. Features:

  • Project creation with client/freelancer roles
  • XLM and Stellar token escrow payments
  • Escrow funding and release on work approval
  • Work submission with GitHub repository linking
  • Dispute resolution and arbitration

Backend

Express.js API server providing:

  • AI Work Verification — Validates freelancer deliverables against project requirements using AI
  • Bulk Verification Operations — Batch verify, update, and delete verification records
  • AI Invoice Generation — Automated invoice creation for completed work
  • Stellar Horizon Integration — On-chain payment status and transaction lookups
  • Scheduled Jobs — Cron-like tasks for background maintenance and monitoring

Bulk Verification Endpoints

  • POST /api/v1/verification/verify/batch
  • PATCH /api/v1/verification/batch
  • DELETE /api/v1/verification/batch

Subscription Endpoints

  • POST /api/v1/plans - Create a subscription plan (Daily, Weekly, Monthly, Yearly)
  • GET /api/v1/plans/:merchantId - Retrieve plans for a specific merchant
  • POST /api/v1/subscriptions/enroll - Enroll a customer in a plan
  • DELETE /api/v1/subscriptions/:id - Cancel an active subscription

Features

  • Instant Payments — Funds released immediately upon work approval via Soroban
  • Blockchain Escrow — Smart contract holds funds securely until milestones are met
  • Subscription Engine — Automated recurring payments for SaaS, payroll, and retainers
  • Social & Wallet Login — Connect via Google/Twitter or Freighter wallet
  • AI Verification — Automated code review against project specifications
  • Milestone Tracking — Track project progress with clear status updates
  • Invoice Management — Auto-generated invoices for completed projects
  • Two-Factor Authentication — TOTP-based 2FA using authenticator apps with backup codes for account security

Devcontainer (recommended)

For one-click setup with Node.js, Rust, Soroban CLI, Postgres, and Redis, see docs/DEVCONTAINER.md.

# One-command stack: Postgres, Redis, backend, and frontend
scripts/devcontainer.sh up

# Or start only the infra (Postgres + Redis) on the host:
docker compose up -d

# Or the full app (infra + backend API + frontend) from the root compose file:
make up-app
make db-migrate   # first run against a new database

Generated SDKs

Typed clients are generated from the backend OpenAPI spec. CI regenerates them on every push.

cd backend && npm run sdk:generate:typescript   # also: sdk:generate:python, sdk:generate:go

This runs the pinned openapi-generator-cli Docker image, so Docker is required. Use node scripts/sdk/generate-sdk.mjs typescript --print to see the command without running it. Settings come from backend/openapi-generator.config.json.

Prerequisites

Before setting up the project locally, ensure you have the following installed:

Required

  • Node.js 20+ — Download from nodejs.org
  • npm 10+ — Comes with Node.js
  • Git — For cloning the repository

Optional (for smart contract development)

  • Rust 1.70+ — Install from rustup.rs
  • Soroban CLI — Install with cargo install soroban-cli
  • Docker — For Soroban local network (optional)

Accounts & Keys


Local Setup

1. Clone the Repository

git clone https://github.com/Smartdevs17/agenticpay.git
cd agenticpay

2. Backend Setup

The backend is an Express.js API server that handles AI verification, invoicing, and Stellar integration.

Install Dependencies

cd backend
npm install
cd ..

Configure Environment Variables

Create a .env file in the backend directory:

cp backend/.env.example backend/.env

Edit backend/.env with your configuration:

# Server Configuration
PORT=3001
NODE_ENV=development

# CORS Configuration
CORS_ALLOWED_ORIGINS=http://localhost:3000,http://localhost:3001

# Stellar Configuration
STELLAR_NETWORK=testnet

# AI Services
OPENAI_API_KEY=sk_test_your_actual_key_here

# Background Jobs
JOBS_ENABLED=true

Environment Variables Reference

Variable Default Description Required
PORT 3001 Server port No
NODE_ENV development Environment (development/production) No
CORS_ALLOWED_ORIGINS * Comma-separated list of allowed origins No
STELLAR_NETWORK testnet Stellar network (testnet/public) No
OPENAI_API_KEY - OpenAI API key for AI verification/invoicing Yes
JOBS_ENABLED true Enable background job scheduler No

3. Frontend Setup

The frontend is a Next.js application providing the web interface for project management and payments.

Install Dependencies

cd frontend
npm install
cd ..

Configure Environment Variables

Create a .env.local file in the frontend directory:

cp frontend/.env.example frontend/.env.local

Edit frontend/.env.local with your configuration:

# Backend API
NEXT_PUBLIC_API_URL=http://localhost:3001/api/v1

# Web3Auth Configuration
NEXT_PUBLIC_WEB3AUTH_CLIENT_ID=your_web3auth_client_id_here

# Stellar Smart Contract
NEXT_PUBLIC_CONTRACT_ADDRESS=0xyour_deployed_contract_address_here

# Theme (optional)
NEXT_PUBLIC_APP_NAME=AgenticPay

Environment Variables Reference

Variable Default Description Required
NEXT_PUBLIC_API_URL http://localhost:3001/api/v1 Backend API URL No
NEXT_PUBLIC_BACKEND_URL http://localhost:3001/api/v1 Fallback backend URL (used if NEXT_PUBLIC_API_URL is unset) No
NEXT_PUBLIC_WEB3AUTH_CLIENT_ID - Web3Auth client ID Yes
NEXT_PUBLIC_CONTRACT_ADDRESS - Deployed Soroban contract address Yes

4. Smart Contracts Setup (Optional)

If you plan to develop or deploy smart contracts, set up the Soroban environment.

Install Rust and Soroban CLI

# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Add WASM target
rustup target add wasm32-unknown-unknown

# Install Soroban CLI
cargo install soroban-cli

Build the Contract

cd contracts
cargo build --target wasm32-unknown-unknown --release

Deploy to Testnet

soroban contract deploy \
  --wasm target/wasm32-unknown-unknown/release/agenticpay.wasm \
  --network testnet \
  --source your_freighter_account

Running the Application

Development Mode

Run all services in development mode:

Terminal 1: Backend Server

cd backend
npm run dev

Backend will start at http://localhost:3001

Terminal 2: Frontend Application

cd frontend
npm run dev

Frontend will start at http://localhost:3000

The application is now running and ready for development at:

Production Build

Build Backend

cd backend
npm run build
npm start

Build Frontend

cd frontend
npm run build
npm start

Testing

Backend Tests

Run the backend test suite:

cd backend
npm test                # Run tests once
npm run test:watch     # Run tests in watch mode

Tests use Vitest and include:

  • Route testing
  • Middleware validation
  • Service logic verification
  • Health check validation

Frontend Tests

Run the frontend test suite:

cd frontend
npm test                # Run tests once
npm run test:watch     # Run tests in watch mode

Tests include:

  • Component rendering
  • User interaction testing
  • API client testing
  • Hook testing

Contract Tests

Build and verify the smart contracts:

cd contracts
cargo test              # Run Rust tests
cargo build --target wasm32-unknown-unknown --release  # Build WASM

API Documentation

Health Check

curl http://localhost:3001/api/v1/health

Verification Endpoints

Create Verification

POST /api/v1/verification/verify
Content-Type: application/json

{
  "projectId": "abc123",
  "freelancerId": "xyz789",
  "deliverables": "GitHub link",
  "requirements": "Build a React component"
}

Batch Verification

POST /api/v1/verification/verify/batch
Content-Type: application/json

{
  "verifications": [
    {
      "projectId": "abc123",
      "freelancerId": "xyz789",
      "deliverables": "GitHub link",
      "requirements": "Build a React component"
    }
  ]
}

Invoice Endpoints

Create Invoice

POST /api/v1/invoice/create
Content-Type: application/json

{
  "projectId": "abc123",
  "freelancerId": "xyz789",
  "amount": "100.50"
}

Stellar Endpoints

Get Transaction Status

GET /api/v1/stellar/transaction/:transactionHash

Troubleshooting

For common issues and solutions, please refer to our Troubleshooting Guide.

Quick Fixes

  • Port Already in Use: lsof -ti:3000,3001 | xargs kill -9
  • Environment Variables: Ensure .env files exist in both backend/ and frontend/ directories.
  • Node Modules: rm -rf node_modules && npm install

Environment Setup Validation

Quick Validation Script

# Check Node.js version
node --version  # Should be 20+

# Check npm version
npm --version   # Should be 10+

# Verify backend environment
cd backend && npm list | head -20

# Verify frontend environment
cd frontend && npm list | head -20

# Test API connectivity
curl -s http://localhost:3001/api/v1/health | jq .

Deployment

Backend Deployment (Vercel/Heroku)

# Set environment variables in hosting platform
# Deploy backend
cd backend
npm run build

Frontend Deployment (Vercel/Netlify)

# Vercel (recommended for Next.js)
npm install -g vercel
vercel

# Or Netlify
npm install -g netlify-cli
netlify deploy

Development Workflow

  1. Create feature branch: git checkout -b feature/your-feature
  2. Make changes and test locally
  3. Run tests: npm test (both backend and frontend)
  4. Commit changes: git commit -am 'Add feature'
  5. Push to branch: git push origin feature/your-feature
  6. Create Pull Request with description

Build caching (Turborepo)

Root build, lint, test and dev scripts run through Turborepo using the task graph in turbo.json. Each task's hash covers the workspace's tracked files, its dependencies' hashes, NODE_VERSION, and NEXT_PUBLIC_* for builds. When the hash is unchanged, turbo restores the cached outputs (dist/, .next/ without .next/cache, coverage/) and skips the task.

Where Cache
Local node_modules/.cache/turbo. Run npx turbo run build --force to bypass it.
CI (.github/workflows/ci.yml) Shared remote cache when it is configured. Otherwise a per-job actions/cache fallback. Each backend/frontend job writes a cache hit/miss table to the run summary.

To enable the shared remote cache, a maintainer sets these in Settings → Secrets and variables → Actions:

Name Kind Purpose
TURBO_TOKEN secret Remote cache access token
TURBO_TEAM variable Remote cache team slug
TURBO_REMOTE_CACHE_SIGNATURE_KEY secret HMAC key. Artifacts are signed (remoteCache.signature), and unsigned or tampered artifacts are ignored
TURBO_API variable, optional Self-hosted cache server URL. Defaults to https://vercel.com/api

To use the remote cache locally, run npx turbo login && npx turbo link, or export the same variables. If the cache is unreachable or the signing key is missing, turbo prints a warning and rebuilds. The build never fails because of the cache.

CI calls turbo@${TURBO_VERSION}, which must match the version in package-lock.json. The config uses the turbo 1.x pipeline schema. scripts/turbo-config.test.mjs checks the version pin and the pipeline contract (node --test scripts/*.test.mjs), and the Repo tooling CI job runs that test.


Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Follow the code style (ESLint configured)
  4. Add tests for new features
  5. Submit a pull request

License

MIT License - See LICENSE file for details


Support

For issues, questions, or suggestions:

  • Issues: GitHub Issues
  • Discussions: GitHub Discussions
  • Documentation: Start with the documentation index

Quick Reference Commands

The root Makefile maps every common dev task to a make target. Run make on its own to list them all, grouped by area.

make doctor              # check Node 20+, npm, cargo, forge, docker
make setup               # npm workspaces + contract toolchains
make dev                 # backend + frontend in watch mode (or dev-backend / dev-frontend)
make test                # every workspace suite; test-backend / test-frontend / test-contracts / test-e2e
make test-backend FILE=src/services/__tests__/settlementProof.test.ts   # a single file
make lint build          # turbo-cached lint and build
make db-migrate db-seed  # database lifecycle (db-reset needs CONFIRM=1)
make sandbox-up          # local sandbox stack (sandbox-down / sandbox-reset / sandbox-logs)
make clean               # remove build outputs and turbo caches

Every target wraps the npm, cargo, forge or docker command it names, and make -n <target> prints that command without running it. You can override tool binaries (NPM=pnpm, COMPOSE="podman compose"). Set VERBOSE=1 to echo commands and TIMINGS=1 to print how long each target took. If a required tool is missing, the target fails with an install hint. scripts/makefile.test.mjs checks that every target is documented, that every npm script a target calls exists, and that every root npm script has a target. Run it with make test-tooling.


External Resources

Environment Variables

Variable Description
NEXT_PUBLIC_CONTRACT_ID Deployed Soroban contract ID
NEXT_PUBLIC_WEB3AUTH_CLIENT_ID Web3Auth client ID for social login
NEXT_PUBLIC_BACKEND_URL Backend API base URL
NEXT_PUBLIC_STELLAR_NETWORK testnet or public
OPENAI_API_KEY OpenAI API key for AI verification
STELLAR_SECRET_KEY Server-side Stellar signing key
JOBS_ENABLED Set to false to disable scheduled jobs

Scheduled Jobs

  • Default jobs live under backend/src/jobs
  • Job status endpoint: GET /api/v1/jobs

Contract Verification

The AgenticPay smart contract source code is published for on-chain verification. To verify the deployed contract matches the source:

Build the contract from source

cd contracts
cargo build --target wasm32-unknown-unknown --release

Verify the WASM hash matches the deployed contract

scripts/verify-contract-hash.sh fetches the deployed WASM from Stellar, hashes it, compares it with the locally built WASM and with contracts/build-manifest.json:

./scripts/verify-contract-hash.sh --contract-id $SOROBAN_CONTRACT_ID --network testnet

After a verified deployment, regenerate the manifest that the backend reads at startup (commit it with the release):

./scripts/verify-contract-hash.sh --contract-id $SOROBAN_CONTRACT_ID --network testnet --write

The manifest records the contract ID, network and expected WASM SHA-256:

{
  "contractId": "C...",
  "network": "testnet",
  "wasmSha256": "<64 hex chars>",
  "wasmFile": "contracts/target/wasm32-unknown-unknown/release/agenticpay.wasm",
  "builtAt": "2026-01-01T00:00:00.000Z"
}

At startup the backend fetches the deployed bytecode via Soroban RPC, hashes it and compares it with the manifest. Behaviour is controlled by CONTRACT_HASH_VERIFICATION:

Value Behaviour
enforce Default. Refuse to start on any mismatch or manifest error.
warn Log the failure and continue starting (rollout / debugging only).
off Skip the check entirely.

Verification is active only when SOROBAN_CONTRACT_ID is set. On the public network SOROBAN_RPC_URL is required; on testnet it defaults to https://soroban-testnet.stellar.org.

Verification status

Network Contract ID Status
Testnet See NEXT_PUBLIC_CONTRACT_ID in .env Source published

Note: Deterministic builds require the same Rust toolchain version. See contracts/Cargo.toml for the SDK version and use rust-toolchain.toml if present.

Network

Currently configured for Stellar Testnet.

Contributing

We welcome contributions! This project participates in the Stellar Wave Program via Drips. Check the issues labeled Stellar Wave for bounty-eligible tasks.

License

MIT

Recent Platform Capabilities

  • Branded Payment Links & Checkout Analytics (backend/src/services/paymentLinks.ts, frontend/app/pay/): Track checkout funnel events (view, checkout_started, completed, abandoned), conversion/abandonment rates, revenue, and merchant-level summaries.
  • Customizable Project Workflow Templates (backend/src/services/templates.ts): Instantiate parameterized workflows from templates via instantiateWorkflow with typed variable validation, {{variable}} interpolation, and per-step configuration overrides.
  • User Reputation & Challenge-Response Resets (backend/src/services/reputation.ts): Score tracking, trust tiers, velocity gaming detection, and HMAC-SHA256 challenge-response resets (initiateReputationReset / completeReputationReset) with single-use TTL enforcement.
  • On-Chain Receipt Verification & QR Codes (contracts/src/lib.rs, backend/src/services/receipts.ts): Canonical SHA-256 on-chain receipt hashes (get_receipt_hash / verify_receipt) paired with HMAC-signed verification QR codes (generateReceiptQrCode / verifyReceiptQrPayload).

About

AgenticPay - AI Agent Payment Infrastructure on blockchain

Resources

Contributing

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages