Back to home

CLPAY Documentation

Complete guide to integrating autonomous Solana payments into your Claude workflows. From installation to production deployment.

Installation

Install CLPAY via npm:

npm install @clpay/core @clpay/validator

Or with yarn:

yarn add @clpay/core @clpay/validator

Requirements

Quick Start

Get up and running in under 5 minutes:

import { CLPay } from '@clpay/core';

const clpay = new CLPay({
  network: 'devnet',
  wallet: './keys/dev-wallet.json',
  limits: { perTransaction: 0.1, daily: 1.0 },
  riskThreshold: 0.5,
});

// Make a payment
const result = await clpay.pay({
  to: 'merchant-address.sol',
  amount: 0.01,
  reason: 'API access for data analysis',
  taskContext: 'User requested market data aggregation',
});

console.log(result);
// {
//   status: 'approved',
//   txHash: '4xK2...9mPq',
//   riskScore: 0.08,
//   necessity: 'high',
//   simulation: { success: true, balanceChange: -0.01 }
// }

Configuration

Full configuration reference for the CLPay constructor:

OptionTypeDefaultDescription
networkstring'devnet'Solana cluster: mainnet-beta, devnet, testnet
walletstringPath to wallet keypair JSON file
limits.perTransactionnumber0.1Max SOL per single transaction
limits.dailynumber1.0Max SOL per 24-hour rolling window
riskThresholdnumber0.5Max acceptable risk score (0–1)
allowliststring[][]Trusted recipient addresses
blockliststring[][]Blocked recipient addresses
validator.simulatebooleantrueEnable transaction simulation
validator.checkContractbooleantrueEnable contract security analysis
validator.evaluateNecessitybooleantrueEnable AI necessity evaluation
onApprovefunctionCallback after approved transaction
onRejectfunctionCallback after rejected transaction

API Reference

clpay.pay(options)

Initiate a payment through the full validation pipeline.

const result = await clpay.pay({
  to: string,          // Recipient address or .sol domain
  amount: number,      // Amount in SOL
  token?: string,      // SPL token mint (default: native SOL)
  reason: string,      // Why this payment is needed
  taskContext: string,  // Current task description for necessity eval
  priority?: 'low' | 'medium' | 'high',  // Transaction priority
  memo?: string,       // On-chain memo
});

Returns a PaymentResult object:

{
  status: 'approved' | 'rejected' | 'pending',
  txHash?: string,           // Solana transaction signature
  riskScore: number,         // 0–1 risk assessment
  necessity: 'high' | 'medium' | 'low' | 'none',
  simulation: {
    success: boolean,
    balanceChange: number,
    logs: string[],
  },
  rejection?: {
    reason: string,          // Human-readable rejection reason
    code: string,            // Machine-readable code
    details: object,         // Additional context
  }
}

clpay.simulate(options)

Simulate a transaction without executing it. Same parameters as pay().

const sim = await clpay.simulate({
  to: 'merchant.sol',
  amount: 0.05,
  reason: 'Testing simulation',
});
// sim.balanceChange, sim.logs, sim.success

clpay.getBalance()

Get current wallet balance.

const balance = await clpay.getBalance();
// { sol: 2.45, tokens: [{ mint: '...', amount: 100, symbol: 'USDC' }] }

clpay.getHistory(options?)

Retrieve transaction history with filtering.

const history = await clpay.getHistory({
  limit: 20,
  status: 'approved',    // 'approved' | 'rejected' | 'all'
  from: new Date('2026-01-01'),
  to: new Date(),
});

Validator Agent

The validator is a side-agent that runs before every transaction. It operates as an independent decision-maker with its own evaluation pipeline.

Pipeline Stages

Custom Stages

You can add custom validation stages:

import { CLPay, ValidationStage } from '@clpay/core';

class ApprovalStage extends ValidationStage {
  async validate(tx) {
    if (tx.amount > 0.1) {
      // Require human approval for large transactions
      const approved = await this.requestHumanApproval(tx);
      return approved
        ? { pass: true }
        : { pass: false, reason: 'Human rejected the transaction' };
    }
    return { pass: true };
  }
}

const clpay = new CLPay({
  // ...config
  validator: {
    customStages: [new ApprovalStage()],
  },
});

Risk Engine

The risk engine produces a score from 0 (safe) to 1 (dangerous) based on multiple signals:

SignalWeightDescription
Recipient reputation0.25Known merchant vs unknown address
Contract verification0.20Verified source code, audit status
Transaction pattern0.15Unusual amounts, frequency, timing
Simulation result0.20Unexpected state changes or failures
Historical behavior0.10Past interactions with this recipient
Network conditions0.10Congestion, fee spikes, anomalies

⚠ Transactions with a risk score above your configured riskThreshold are automatically blocked. The default threshold is 0.5. For production use with real funds, we recommend starting at 0.3.

Security Model

Key Management

Private keys are never exposed to the AI agent. The wallet module handles all cryptographic operations in an isolated context:

Threat Model

Events & Hooks

CLPAY emits events at every stage of the payment lifecycle:

clpay.on('payment:initiated', (tx) => { /* ... */ });
clpay.on('validation:stage', (stage, result) => { /* ... */ });
clpay.on('payment:approved', (tx, result) => { /* ... */ });
clpay.on('payment:rejected', (tx, reason) => { /* ... */ });
clpay.on('payment:executed', (tx, signature) => { /* ... */ });
clpay.on('limit:warning', (usage) => { /* 80% of daily limit */ });
clpay.on('limit:reached', (usage) => { /* daily limit hit */ });

CLI

CLPAY includes a CLI for wallet management and monitoring:

# Check wallet balance
npx clpay balance

# View transaction history
npx clpay history --limit 10

# Test a payment (simulation only)
npx clpay simulate --to merchant.sol --amount 0.01

# Export audit log
npx clpay audit --format json --output audit.json

# Manage allowlist
npx clpay allow add openai.merchant.sol
npx clpay allow list
npx clpay allow remove openai.merchant.sol

💡 All CLI commands support --network flag to specify the Solana cluster. Default is devnet.