v0.1 — Beta

Installation

bash
npm install @mppcash/sdk

Initialize the client

typescript
import { MPPCash } from "@mppcash/sdk";

// Operator client — for provisioning, policy, and management
const client = new MPPCash({
  apiKey: process.env.MPPPAL_API_KEY,
});

Wallets

typescript
// Provision a new agent wallet
const wallet = await client.accounts.create({
  name: "research-agent-prod",
});
console.log(wallet.account_id);        // acct_01j8k4x9p2qrst7yz
console.log(wallet.solana_address);    // 9xTz4KqR8...
console.log(wallet.usdc_token_account); // Fund this with USDC

// Get balance
const { balance_usdc } = await client.accounts.getBalance("acct_01j8k4x9p2qrst7yz");

// List wallets
const { data } = await client.accounts.list({ limit: 50 });

MPP Agent

The MPPCash.Agent class wraps wallet credentials and handles MPP payment challenges automatically. Use it in agent code — not in operator/management code.

typescript
// Agent-side: use agent-scoped key, not operator key
const agent = new MPPCash.Agent({
  wallet: process.env.MPPPAL_WALLET_ID,
  apiKey: process.env.MPPPAL_AGENT_KEY,
  intent: "session",      // "charge" | "session"
  sessionCap: "5.00",
});

const http = agent.createHttpClient();

// HTTP 402 challenges resolved automatically
const result = await http.get("https://api.someservice.xyz/inference");

// Close session explicitly to trigger immediate settlement
const receipt = await agent.closeSession();
console.log(receipt.tx_signature); // Solana settlement tx

Direct transfers

typescript
const transfer = await client.transfers.create({
  from: "acct_01j8k4x9p2qrst7yz",
  to: "acct_02k9n5y3q7wpuv8ab",  // MPPCash account_id or raw SPL address
  amount: "8.50",
  memo: "Task reward: data-fetch-88",
  idempotency_key: "task-88-reward",
});

console.log(transfer.status);       // "settled"
console.log(transfer.tx_signature); // Solana signature

Policy

typescript
// Update policy (operator key required)
await client.policy.update("acct_01j8k4x9p2qrst7yz", {
  max_single_transfer: 10,
  max_daily_spend: 100,
  categories: ["inference", "data"],
  require_memo: true,
  paused: false,
});

// Emergency pause — immediate effect
await client.policy.pause("acct_01j8k4x9p2qrst7yz");

Error handling

typescript
import { MPPCashError, PolicyViolationError } from "@mppcash/sdk";

try {
  await client.transfers.create({ ... });
} catch (err) {
  if (err instanceof PolicyViolationError) {
    console.error("Blocked by policy:", err.message, err.rule);
    // escalate to operator, log to incident system, etc.
  } else if (err instanceof MPPCashError) {
    console.error("API error:", err.code, err.message);
  } else {
    throw err;
  }
}

TypeScript types

TypeDescription
AccountFull wallet object with balance and policy
TransferSettled or rejected transfer record
SpendingPolicyPolicy configuration object
MppSessionActive session with cap, running total, and status
SessionReceiptClosed session settlement record with tx_signature
WebhookPayload<T>Generic webhook envelope, parameterized by event type
MPPCashErrorBase error class with code, message, status
PolicyViolationErrorExtends MPPCashError, includes rule that was violated