JSPM

@asgcard/pay

0.1.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 918
  • Score
    100M100P100Q8224F
  • License MIT

Production x402/MPP payment SDK for AI agents โ€” autonomous 402 settlement on 15 networks (EVM + Stellar + Solana + Stripe) with fail-closed policy engine.

Package Exports

  • @asgcard/pay

Readme

๐Ÿš€ OWS Agent Pay

Autonomous Payment SDK for AI Agents

OWS-compliant โ€ข x402 Protocol โ€ข Multi-chain โ€ข Policy-gated

License: MIT OWS v1.0.0 x402 npm Base Stellar Built by ASG Pay

The AI agent simply calls performTask() โ€” the SDK handles payment, policy validation, on-chain settlement, and proof generation transparently.

Documentation โ€ข โ–ถ Live Demo โ€ข Architecture โ€ข Live Products โ€ข OWS Compliance

๐ŸŽฎ Try the interactive demo โ†’ โ€” no install, no wallet, no ETH needed. Watch the full x402 flow in your browser.

๐ŸŒ View the full ecosystem demo โ†’ โ€” Fund โ†’ Card โ†’ Pay: the complete autonomous agent financial stack.


๐Ÿ’ก What This Solves

AI agents are rapidly becoming autonomous economic actors, but they have no native way to pay for services programmatically. OWS Agent Pay bridges this gap:

AI Agent calls API โ†’ Server returns HTTP 402 โ†’ SDK auto-pays โ†’ Agent gets result

Zero payment code required from the agent developer. The SDK intercepts, validates, settles, and retries โ€” all transparently.

โš ๏ธ This is not a hackathon prototype. We extracted the core x402 payment logic from our live production stack (10K+ monthly NPM downloads) into a clean, OWS-compliant SDK.


โšก Quick Start

Option 1: Browser Demo (Zero Install)

โ–ถ Open the live demo โ†’ โ€” click "Run Live Demo" and watch the full x402 cycle in 30 seconds.

Option 2: CLI Demo

# Clone and install
git clone https://github.com/ASGCompute/ASGCompute-ows-agent-pay.git
cd ASGCompute-ows-agent-pay
npm install

# Run the demo (simulated mode โ€” no ETH needed)
npx ts-node demo.ts --simulate

# Or run with real Base Sepolia testnet (auto-funds via Coinbase faucet)
npx ts-node demo.ts

Option 3: Use in Your Agent

import { OwsClient, BasePaymentAdapter } from 'ows-agent-pay';

const adapter = new BasePaymentAdapter({
  privateKey: process.env.AGENT_PRIVATE_KEY as `0x${string}`,
  network: 'mainnet',
});

const agent = new OwsClient({
  baseURL: 'https://inference-api.example.com',
  policy: {
    monthlyBudget: 100,
    maxAmountPerTransaction: 5,
    allowedDestinations: ['0x...'],
  },
  adapter, // Swap to StellarPaymentAdapter for Stellar
});

// Agent code โ€” no payment logic needed!
const result = await agent.performTask('/v1/chat', {
  model: 'gpt-4',
  messages: [{ role: 'user', content: 'Summarize this document' }],
});

Expected CLI Output

โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘   OWS Agent Pay โ€” Base/EVM Autonomous Demo      โ•‘
โ•‘   Built by ASG Pay  โ€ข  https://asgcard.dev       โ•‘
โ•‘   x402 Protocol  โ€ข  Base (Coinbase L2)           โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

[Server] Mock API listening on http://localhost:4020
[Agent] Wallet: 0xAb5801a7D398991B8a7cF7706226...
[Agent] Chain:  Base Sepolia (eip155:84532)
[Agent] ๐Ÿ’ง Requesting ETH from Base Sepolia faucetโ€ฆ
[Agent] โœ… Wallet funded from Coinbase faucet
[Agent] ๐Ÿ’ฐ Balance: 0.1 ETH
[Agent] ๐Ÿง  Sending inference requestโ€ฆ

[OWS Client] โšก Received 402 Payment Required challenge
[OWS Client] ๐Ÿ’ฐ Requested payment: $0.50
[OWS Client] โ›“๏ธ  Settlement chain: Base (eip155:84532)
[OWS Client] โœ… Policy check PASSED โ€” settling on-chainโ€ฆ
[Base] ๐Ÿš€ Building payment โ†’ 0xDead71โ€ฆ8B3c4F (0.0005 ETH, Base Sepolia)
[Base] ๐Ÿ“ก Submitting transactionโ€ฆ
[Base] โœ… Confirmed โ€” hash: 0x9e8f7a6b5c4d3e2fโ€ฆ
[OWS Client] ๐Ÿ” Constructing X-PAYMENT token and retryingโ€ฆ

[AI Agent] โœ… Task completed: The AI model computed the answer...

โ”€โ”€ ๐Ÿ Demo complete โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

๐Ÿ—๏ธ Architecture

                            โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                            โ”‚    AI  Agent      โ”‚
                            โ”‚  performTask()    โ”‚
                            โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                     โ”‚ HTTP POST
                            โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                            โ”‚   OwsClient       โ”‚
                            โ”‚  (Axios + 402     โ”‚
                            โ”‚   interceptor)    โ”‚
                            โ””โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”˜
                              โ”‚              โ”‚
               โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
               โ”‚  PolicyEngine   โ”‚   โ”‚  PaymentAdapter    โ”‚
               โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚   โ”‚  (interface)       โ”‚
               โ”‚  โ”‚ Budget     โ”‚ โ”‚   โ”‚                    โ”‚
               โ”‚  โ”‚ Per-tx max โ”‚ โ”‚   โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
               โ”‚  โ”‚ Allowlist  โ”‚ โ”‚   โ”‚  โ”‚ Base (viem)  โ”‚  โ”‚
               โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚   โ”‚  โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค  โ”‚
               โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚  โ”‚ Stellar      โ”‚  โ”‚
                                     โ”‚  โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค  โ”‚
                                     โ”‚  โ”‚ (Arbitrumโ€ฆ)  โ”‚  โ”‚
                                     โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
                                     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
Component File Purpose
OwsClient client.ts Chain-agnostic Axios wrapper with 402 interceptor
PolicyEngine policy.ts Fail-closed budget, per-tx limits, destination allowlist
BasePaymentAdapter adapters/base.ts On-chain settlement via Base (Coinbase L2) using viem
StellarPaymentAdapter adapters/stellar.ts On-chain settlement via Stellar network
PaymentAdapter adapters/types.ts Generic interface โ€” plug in any chain (~40 lines)

๐Ÿ“ OWS Spec Compliance

OWS Section Requirement Implementation
ยง03 Intercept Detect 402 Payment Required Axios response interceptor (client.ts:44)
ยง04 Evaluate Validate x402Version + accepts[] Envelope parser + PolicyEngine (policy.ts)
ยง05 Settle Execute on-chain payment BasePaymentAdapter / StellarPaymentAdapter
ยง06 Prove Attach X-PAYMENT header Base64-encoded proof with tx hash + CAIP-2 chain ID
ยง07 Retry Resubmit original request Axios re-request with proof header
ยง08 Chains CAIP-2 chain identifiers eip155:8453 (Base), eip155:84532 (Sepolia), stellar:testnet

๐Ÿ” Policy Engine (Fail-Closed)

Every payment must pass all three checks before execution:

const policy: BudgetPolicy = {
  monthlyBudget: 50.0,           // USD cap per calendar month
  maxAmountPerTransaction: 5.0,  // USD cap per single payment
  allowedDestinations: [         // Whitelist of recipient addresses
    '0xDead7101a13B2B6e2A4497706226bc3c4F',
  ],
};

โŒ Over budget โ†’ REJECTED
โŒ Over per-tx limit โ†’ REJECTED
โŒ Unknown destination โ†’ REJECTED
โœ… All checks pass โ†’ SETTLED


โ›“๏ธ Supported Chains

Chain Adapter CAIP-2 Status
Base (Coinbase L2) BasePaymentAdapter eip155:8453 โœ… Live
Base Sepolia BasePaymentAdapter eip155:84532 โœ… Testnet
Stellar StellarPaymentAdapter stellar:pubnet โœ… Live
Arbitrum EvmPaymentAdapter eip155:42161 ๐Ÿ”œ Next
Solana SolanaPaymentAdapter solana:mainnet ๐Ÿ”œ Planned
Sui SuiPaymentAdapter sui:mainnet ๐Ÿ”œ Planned

๐Ÿ’ก Any chain can be added by implementing the PaymentAdapter interface (~40 lines).


๐ŸŒ Live Production Products

This is not a hackathon prototype. Every product below is deployed and serving real traffic right now.

๐Ÿ”— Try them yourself

๐Ÿ’ณ ASG Pay

Universal Payment Gateway

The AI agent payment infrastructure. Accept fiat and crypto across 60+ chains.

โ–ถ pay.asgcard.dev

npm install @asgcard/pay

๐Ÿ’ฐ ASG Fund

Agent Wallet Funding

Top up any AI agent's wallet with USDC on Stellar โ€” via card, bank, or stablecoin.

โ–ถ fund.asgcard.dev

npm install @asgcard/fund

๐Ÿƒ ASG Card

Virtual Cards for AI Agents

Issue virtual debit cards on demand. Pay via x402 or Stripe Machine Payments.

โ–ถ asgcard.dev

npx @asgcard/cli

๐Ÿ“ฆ NPM Packages

Package Install Downloads Description
@asgcard/pay npm i @asgcard/pay npm Core payment SDK
@asgcard/fund npm i @asgcard/fund npm Payment link generator CLI
@asgcard/cli npx @asgcard/cli npm Virtual card issuing CLI

๐ŸŽฎ Interactive Demos

Demo URL What You'll See
Browser Demo โ–ถ index.html Full x402 cycle: 402 โ†’ Policy โ†’ Settlement โ†’ Proof โ†’ Result. Zero install.
Ecosystem Demo โ–ถ ecosystem.html 3 interactive tabs: Fund Agent โ†’ Issue Card โ†’ x402 Pay โ€” each with live terminal.
Fund Agent โ–ถ fund.asgcard.dev Real agent wallet ($14.37 USDC + XLM on Stellar mainnet).
Issue Card โ–ถ asgcard.dev Virtual debit card issuance for AI agents via x402 + Stripe.

๐Ÿ† Hackathon Track Alignment

Track Alignment
๐Ÿ’ฐ Payments โญ Core โ€” x402 autonomous settlement on Base
๐Ÿค– AI Agents โญ Core โ€” transparent payment layer for agents
๐Ÿ”’ Agent Spend Governance โญ Core โ€” PolicyEngine (fail-closed budget control)
๐Ÿ”— Interoperability Multi-chain adapters via CAIP-2
๐Ÿ—๏ธ Infrastructure Production SDK + ASG Pay ecosystem

๐Ÿค Sponsor & Partner Alignment

Base
Primary settlement
Native x402 chain
Circle
USDC settlement
EVM + Stellar
Stellar
Production adapter
Mainnet USDC
Arbitrum
EVM adapter
Roadmap
Stripe
Fiat settlement
fund.asgcard.dev
Li.Fi
Cross-chain
Aggregator
ROZO
Bridging
Partner

๐Ÿ›ฃ๏ธ Roadmap

  • OWS-compliant 402 interceptor with policy engine
  • Base adapter (viem, Coinbase L2 โ€” native x402 chain)
  • Stellar adapter (production-proven via ASG Pay)
  • Multi-chain adapter interface (CAIP-2)
  • Interactive browser demo (GitHub Pages)
  • Full ecosystem demo (Fund โ†’ Card โ†’ Pay lifecycle)
  • Arbitrum / OP Stack adapters
  • Solana adapter (via @solana/web3.js)
  • Li.Fi integration (cross-chain settlement aggregator)
  • MCP tool server (A2A protocol bridge)
  • USDC (ERC-20) transfer support on Base

๐Ÿ“Š Key Metrics

Metric Value
NPM Downloads 10K+ monthly (@asgcard)
SDK Size ~529 lines TypeScript
Dependencies 3 (viem, axios, @stellar/stellar-sdk)
Chains Live 2 (Base + Stellar)
Products Live 3 (pay, fund, card) โ€” all in production
OWS Compliance 6/6 specification sections
License MIT

๐Ÿ“„ License

MIT โ€” see LICENSE for details.


Built with โค๏ธ by ASG Compute

pay.asgcard.dev โ€ข fund.asgcard.dev โ€ข asgcard.dev

Autonomous payments for autonomous agents.

โ–ถ Try the Live Demo โ€ข ๐Ÿ“ฆ NPM โ€ข ๐Ÿฆ Twitter