StackA2A
enterprisetypescript

Agentic Economy Boilerplate

34

by xpaysh

๐Ÿš€ The Rosetta Stone for Agentic Payments - One vending machine, 5+ protocol implementations. Get from zero to working agentic payments in 5 minutes.

7 starsUpdated 2026-01-05MIT
Quality Score34/100
โ˜… Community
20
โ—ท Freshness
71
โœ“ Official
30
โšก Skills
10
โฌก Protocol
30
๐Ÿ”’ Security
20

Getting Started

1Clone the repository
$ git clone https://github.com/xpaysh/agentic-economy-boilerplate
2Navigate to the project
$ cd agentic-economy-boilerplate
3Install dependencies
$ npm install
4Run the agent
$ npm start

README

Agentic Economy Boilerplate

The Rosetta Stone for Agentic Payments - One vending machine, multiple protocol implementations + production utilities

Get from zero to working agentic payments in 5 minutes with our battle-tested boilerplate examples.

License: MIT CI PRs Welcome Main Repository Protocols Setup Time

๐ŸŽฏ Quick Start

๐Ÿ”ฅ The 5-Minute Challenge

Pick any protocol and get a working payment agent running:

# Clone this repository
git clone https://github.com/xpaysh/agentic-economy-boilerplate
cd agentic-economy-boilerplate

# Choose your adventure:
cd x402-vending-machine && npm install && npm start          # Crypto micropayments โœ…
cd ap2-vending-machine && npm install && npm start           # Enterprise authorization โœ…
cd acp-vending-machine && npm install && npm start           # Consumer checkout โœ…
cd mastercard-vending-machine && npm install && npm start    # TradFi integration โœ…

# Your vending machine is now live! ๐ŸŽ‰

๐Ÿณ Or Use Docker

# Start all vending machines + Redis with one command
docker-compose up

# Or start individual services
docker-compose up x402-vending
docker-compose up mastercard-vending

# For development (just Redis + Redis Commander)
docker-compose -f docker-compose.dev.yml up

โœจ What's New

๐ŸŽ Production-Ready Shared Utilities

All vending machines now have access to enterprise-grade utilities:

  • ๐Ÿ“ฆ Storage Layer: Redis with automatic in-memory fallback
  • ๐Ÿ›ก๏ธ Security Suite: Rate limiting, agent detection, input sanitization
  • ๐Ÿงช Testing Framework: Mock agents, payment helpers, comprehensive fixtures
  • ๐Ÿณ Docker Infrastructure: Production & development compose files
  • ๐Ÿ“Š Middleware: Logging, error handling, CORS, Helmet

See shared/ for complete documentation on all utilities.

๐Ÿ—๏ธ What You'll Build

Each example implements the same Digital Vending Machine that:

  • โœ… Accepts payments via different protocols
  • โœ… Dispenses digital products (JSON responses)
  • โœ… Handles errors gracefully
  • โœ… Includes security best practices
  • โœ… Provides detailed logging
  • โœ… NEW: Uses production-ready shared utilities

The Power: Compare protocols side-by-side with identical functionality.

๐Ÿ“ฆ Available Implementations

โœ… x402 Vending Machine

Protocol: Coinbase x402 Best For: Crypto micropayments, AI agent APIs Features: HTTP 402 status code, instant settlement, zero fees Status: โœ… Production Ready (with shared utilities)

cd x402-vending-machine
curl http://localhost:3000/inventory
curl http://localhost:3000/buy/classic-cola
# Returns: 402 Payment Required with x402 headers

Full Documentation

โœ… AP2 Vending Machine

Protocol: Google Agent Payments Protocol (AP2) Best For: Enterprise workflows, auditable payments Features: Verifiable credentials, mandate-based authorization, audit trails Status: โœ… Working (can be upgraded with shared utilities)

cd ap2-vending-machine
npm start
# Accepts AP2 credentials and multi-rail payments

Full Documentation

โœ… ACP Vending Machine

Protocol: OpenAI Agentic Commerce Protocol (ACP) Best For: Consumer AI commerce, chat interfaces Features: Stripe integration, fraud prevention, AI agent detection Status: โœ… Working (can be upgraded with shared utilities)

cd acp-vending-machine
npm start
# Provides ChatGPT-style checkout experience

Full Documentation

โœ… Mastercard Vending Machine

Protocol: Mastercard Agent Pay Best For: Traditional finance integration, global card payments Features: Card processing (Visa/MC/Amex), agent authorization, webhooks Status: โœ… Production Ready (with shared utilities)

cd mastercard-vending-machine
npm install && npm start
# Processes card payments for AI agents

Key Features:

  • Traditional card payment processing (Visa, Mastercard, Amex, Discover)
  • Payment sessions with 15-minute expiry
  • Agent authorization whitelist
  • Webhook support for real-time notifications
  • Mock mode for development
  • Full Mastercard API integration

Full Documentation

๐Ÿšง Coming Soon

Pay3 Vending Machine

Protocol: Pay3 Stablecoin Protocol Best For: DeFi integration, cross-chain payments Status: ๐Ÿ“‹ Planned

Hybrid Examples

Multi-Protocol Smart Agents Status: ๐Ÿ“‹ Planned

See how advanced agents switch between protocols:

  • amount < $1 โ†’ x402 (micropayments)
  • enterprise + audit_required โ†’ AP2 (compliance)
  • chat_context + consumer โ†’ ACP (UX)
  • cross_border + cards โ†’ Mastercard (global reach)

๐Ÿ› ๏ธ Project Structure

agentic-economy-boilerplate/
โ”œโ”€โ”€ shared/                            # ๐ŸŽ NEW: Production-ready utilities
โ”‚   โ”œโ”€โ”€ storage/                       #   Redis + in-memory storage
โ”‚   โ”œโ”€โ”€ middleware/                    #   Rate limiting, agent detection, security
โ”‚   โ”œโ”€โ”€ testing/                       #   Mock agents, fixtures, test helpers
โ”‚   โ””โ”€โ”€ docker/                        #   Dockerfile templates
โ”œโ”€โ”€ x402-vending-machine/              # โœ… HTTP 402 crypto payments
โ”œโ”€โ”€ ap2-vending-machine/               # โœ… Google AP2 enterprise
โ”œโ”€โ”€ acp-vending-machine/               # โœ… OpenAI + Stripe consumer
โ”œโ”€โ”€ mastercard-vending-machine/        # โœ… Mastercard TradFi
โ”œโ”€โ”€ visa-tap-vending-machine/          # ๐Ÿ“‹ Visa Trusted Agent Protocol (planned)
โ”œโ”€โ”€ ack-vending-machine/               # ๐Ÿ“‹ Agent Commerce Kit (planned)
โ”œโ”€โ”€ aep2-vending-machine/              # ๐Ÿ“‹ Agent Embedded Payment Protocol (planned)
โ”œโ”€โ”€ a2a-x402-vending-machine/          # ๐Ÿ“‹ Google A2A + x402 hybrid (planned)
โ”œโ”€โ”€ hybrid-examples/                   # ๐Ÿ“‹ Multi-protocol examples (deferred)
โ”œโ”€โ”€ docker-compose.yml                 # ๐Ÿณ Production deployment
โ”œโ”€โ”€ docker-compose.dev.yml             # ๐Ÿณ Development environment
โ””โ”€โ”€ .env.example                       # ๐Ÿ“ Environment template

๐Ÿ”ง Setup Requirements

Prerequisites

  • Node.js 18+ (all examples)
  • Docker (optional, for containerized deployment)
  • Git (for cloning)
  • Redis (optional, for production storage - Docker Compose includes it)

Protocol-Specific Requirements

Protocol Additional Requirements
x402 Crypto wallet (Base/Ethereum)
AP2 Google Cloud account, enterprise credentials
ACP OpenAI API key, Stripe account
Mastercard Mastercard developer account (or use mock mode)

Environment Setup

Copy and configure the environment template:

# Root level (shared config)
cp .env.example .env

# Protocol-specific
cd x402-vending-machine && cp .env.example .env
cd mastercard-vending-machine && cp .env.example .env
# Edit .env files with your configuration

๐Ÿ“š Documentation

Getting Started

Shared Utilities

Protocol Examples

Planned Protocols

  • Visa TAP - Visa Trusted Agent Protocol
  • ACK - Agent Commerce Kit
  • AEP2 - Agent Embedded Payment Protocol
  • A2A + x402 - Google A2A with x402 payments

๐ŸŽฏ Real-World Use Cases

x402 Examples

  • AI API Monetization: Charge per API call with crypto
  • Data Streaming: Real-time feeds with micropayments
  • Content Access: Paywall without subscriptions

AP2 Examples

  • Enterprise Procurement: Automated B2B purchasing
  • Compliance Workflows: Auditable agent transactions
  • Multi-Party Payments: Complex payment flows

ACP Examples

  • Conversational Commerce: Shop within ChatGPT
  • AI Shopping Assistants: Automated purchase agents
  • Consumer Marketplaces: AI-driven product discovery

Mastercard Examples

  • Traditional Integration: Work with existing card infrastructure
  • Global Payments: Accept payments worldwide
  • Enterprise Agents: Corporate card processing for AI agents
  • Hybrid Systems: Bridge crypto and traditional finance

๐Ÿ” Security Features

Every example includes:

  • โœ… Input validation and sanitization (via shared middleware)
  • โœ… Rate limiting to prevent abuse (configurable per agent type)
  • โœ… Agent detection with trust classification
  • โœ… Audit logging for all transactions
  • โœ… Error handling with proper status codes
  • โœ… Environment variable protection
  • โœ… Helmet security headers and CORS configuration
  • โœ… API key authentication (optional)
  • โœ… Signature verification (optional)

Security Checklist

  • Environment variables configured
  • Rate limits set appropriately
  • Audit logging enabled
  • HTTPS enforced in production
  • Input validation active
  • Agent detection configured
  • Redis password set (if using Redis)
  • Error handling tested

๐Ÿงช Testing

Using Shared Testing Utilities

const { MockAgentClient, fixtures, paymentHelpers } = require('./shared/testing');

// Create a mock AI agent
const agent = new MockAgentClient('openai');

// Use test fixtures
const product = fixtures.products.coffee;

// Test payment flow
const result = await paymentHelpers.testPaymentFlow({
  protocol: 'x402',
  amount: product.price,
  productId: product.id
});

Run Tests

# Install shared utilities first
cd shared && npm install && cd ..

# Run vending machine tests
cd x402-vending-machine
npm test

# Run with coverage
npm run test:coverage

See Testing Guide for comprehensive testing documentation.

๐Ÿš€ Deployment

Local Development

# Start individual vending machine
cd x402-vending-machine
npm run dev

# Or use Docker for full stack
docker-compose -f docker-compose.dev.yml up

Production with Docker

# Start all services (Redis + all vending machines)
docker-compose up -d

# View logs
docker-compose logs -f

# Stop all services
docker-compose down

Environment Variables

# Storage Configuration
USE_REDIS=true
REDIS_URL=redis://localhost:6379

# Security
RATE_LIMIT_WINDOW_MS=60000
RATE_LIMIT_MAX_REQUESTS=100

# Logging
LOG_LEVEL=info
NODE_ENV=production

See Production Deployment Guide for complete instructions.

๐Ÿ“Š Monitoring & Analytics

Built-in Analytics

Each vending machine includes:

  • Transaction volume and success rates
  • Response times and error rates
  • Agent detection statistics
  • Storage backend status (Redis vs in-memory)

Access Analytics

# x402
curl http://localhost:3000/analytics

# Mastercard
curl http://localhost:3003/api/analytics

Integration Options

  • Datadog: APM and infrastructure monitoring
  • New Relic: Application performance monitoring
  • Prometheus: Metrics collection with shared middleware
  • Winston: File and console logging (built-in)

๐Ÿค Contributing

We welcome contributions! Here's how to help:

Add New Protocol Examples

  1. Fork the repository
  2. Use shared/ utilities for consistency
  3. Create new directory: {protocol}-vending-machine/
  4. Follow the structure of existing examples
  5. Add comprehensive README, Dockerfile, and .env.example
  6. Submit pull request

Improve Shared Utilities

  • Add new middleware (caching, compression, etc.)
  • Enhance testing framework
  • Improve storage adapters
  • Add more mock agent behaviors

Improve Existing Examples

  • Integrate shared utilities into AP2 and ACP
  • Add real blockchain verification (x402)
  • Enhance security implementations
  • Optimize performance

Contribution Guidelines

  • Follow existing code style
  • Use shared utilities when possible
  • Add tests for new functionality
  • Update documentation
  • Include security considerations

Documentation

External Resources

๐Ÿ“ˆ Roadmap

Current (v1.0)

  • โœ… 4 working protocol implementations
  • โœ… Production-ready shared utilities
  • โœ… Docker deployment infrastructure
  • โœ… Comprehensive testing framework

Coming Soon (v1.1)

  • ๐Ÿ“‹ Pay3 stablecoin implementation
  • ๐Ÿ“‹ Hybrid multi-protocol examples
  • ๐Ÿ“‹ Real blockchain verification (x402)
  • ๐Ÿ“‹ Complete AP2/ACP shared utility integration

Future (v2.0)

  • ๐Ÿ“‹ Agent-to-agent payment coordination
  • ๐Ÿ“‹ Cross-protocol arbitrage examples
  • ๐Ÿ“‹ Advanced monitoring dashboards
  • ๐Ÿ“‹ Production deployment templates (K8s, Terraform)

๐Ÿ“„ License

MIT License - feel free to use these examples in your projects!


๐Ÿš€ Ready to build the future of autonomous payments?

  1. Quick Start: docker-compose up - Get all vending machines running
  2. Learn: Browse protocol READMEs
  3. Build: Use shared utilities for production features
  4. Deploy: Follow the production guide

Having issues? Check our Docker Quickstart or Testing Guide for help.

Capabilities

StreamingPush NotificationsMulti-TurnAuth: none
agent-to-agentagentic-aiagentic-ai-developmentai-paymentsdocker-boilerplatemicropaymentsx402x402-agentx402-payment
View on GitHub