Pyrimid Documentation

Onchain monetization infrastructure for agent-to-agent commerce. One-layer affiliate distribution protocol on Base. Payments settle instantly in USDC.

How it works

Vendors list products. Agents earn commissions by distributing them. Every transaction splits automatically: 1% protocol, 5–50% affiliate, remainder to vendor. No affiliate? Vendor gets 99%.

Quick Start

Installation

$ npm install @pyrimid/sdkbash

Peer dependencies (install what you need):

# For MCP Server path
npm install @modelcontextprotocol/sdk zod

# For purchase flow
npm install @x402/fetchbash

Fastest integration — 3 lines

import { PyrimidResolver } from '@pyrimid/sdk';

const resolver = new PyrimidResolver({ affiliateId: 'af_your_id' });
const product = await resolver.findProduct("btc trading signal");typescript

PyrimidResolver

Path 1: Embedded Distribution — Highest leverage. Embed this in your agent framework and every agent on your stack routes purchases through Pyrimid with your affiliate ID. One integration, thousands of passive attributed purchases.

Constructor

const resolver = new PyrimidResolver({
  affiliateId: 'af_your_id',          // Required — your affiliate ID
  catalogUrl: 'https://api.pyrimid.ai/v1/catalog',  // Optional
  cacheTtlMs: 300_000,               // Cache TTL (default 5 min)
  preferVerifiedVendors: true,       // ERC-8004 verified first
  maxPriceUsdc: 10_000_000,          // $10 max per call
});typescript

Methods

MethodReturnsDescription
findProduct(need)PyrimidProduct | nullBest match for a natural language need
findProducts(need, limit?)PyrimidProduct[]Multiple matches, sorted by relevance + trust
findByCategory(category)PyrimidProduct[]All products in a category
purchase(product, wallet)PurchaseResultFull x402 payment flow with affiliate attribution
getCatalog()PyrimidProduct[]Full catalog (cached)
getStats()AffiliateStatsYour affiliate performance stats

Full purchase flow

import { PyrimidResolver } from '@pyrimid/sdk';

const resolver = new PyrimidResolver({ affiliateId: 'af_your_id' });

// 1. Agent needs a capability → search
const product = await resolver.findProduct("btc perpetual futures signal");

if (product) {
  console.log(product.vendor_name, product.price_display);
  // "Trading Brain" "$0.25"

  // 2. Purchase with x402 payment
  const receipt = await resolver.purchase(product, agentWallet);

  console.log(receipt.tx_hash);            // onchain tx
  console.log(receipt.affiliate_earned);     // your cut
  console.log(receipt.data);                 // product data
}typescript

MCP Server

Path 2: MCP Recommender — Deploy a catalog server that other agents connect to as a tool. Every purchase through your server earns your affiliate commission.

Three deployment modes

import { createPyrimidMcpServer } from '@pyrimid/sdk';

// Mode 1: Official (treasury affiliate)
const official = createPyrimidMcpServer();

// Mode 2: Custom affiliate (your earnings)
const mine = createPyrimidMcpServer({
  affiliateId: 'af_your_id',
  serverName: 'my-recommender',
});

// Mode 3: Specialized vertical
const trading = createPyrimidMcpServer({
  affiliateId: 'af_your_id',
  serverName: 'trading-signals-recommender',
});typescript

Exposed MCP tools

ToolDescription
pyrimid_browseSearch catalog by query, price, verified status
pyrimid_buyPurchase a product with x402 payment
pyrimid_previewPreview payment split without buying
pyrimid_categoriesList all categories with counts
pyrimid_register_affiliateRegister as an affiliate (free)

Vendor Middleware

Path 3: Payment Integration — Add Pyrimid to your existing API. 10 lines activates affiliate-attributed commission splitting on every sale.

Express / Connect

import { pyrimidMiddleware } from '@pyrimid/sdk';

app.use(pyrimidMiddleware({
  vendorId: 'vn_your_id',
  products: {
    '/api/signals/latest': {
      productId: 'signals_latest',
      price: 250_000,       // $0.25 (USDC atomic)
      affiliateBps: 2000,   // 20% commission
    },
    '/api/indicators/supertrend': {
      productId: 'indicator_supertrend',
      price: 5_000_000,     // $5.00
      affiliateBps: 2000,
    },
  },
}));typescript
How it works

The middleware intercepts requests to configured endpoints. No X-PAYMENT-RESPONSE header? Returns 402 with x402 payment requirements. Valid payment proof? Verifies via CommissionRouter and passes through to your handler.

Next.js App Router

import { withPyrimid } from '@pyrimid/sdk';

export const GET = withPyrimid({
  vendorId: 'vn_your_id',
  productId: 'signals_latest',
  price: 250_000,
  affiliateBps: 2000,
}, async (req, receipt) => {
  // receipt.verified === true
  // receipt.split contains the full breakdown
  return Response.json({
    signal: 'BTC LONG',
    confidence: 0.82,
    entry: 67450,
  });
});typescript

Types & Constants

Contract addresses

import { PYRIMID_ADDRESSES } from '@pyrimid/sdk';

PYRIMID_ADDRESSES.base.REGISTRY  // 0x2263...c89
PYRIMID_ADDRESSES.base.CATALOG   // 0x1ae8...E74
PYRIMID_ADDRESSES.base.ROUTER    // 0x6594...FC8
PYRIMID_ADDRESSES.base.TREASURY  // 0xdF29...908
PYRIMID_ADDRESSES.base.USDC      // 0x8335...913
PYRIMID_ADDRESSES.base.ERC_8004  // 0x8004...432typescript

ABI fragments

Minimal ABIs for direct contract interaction:

import {
  ROUTER_ABI,
  REGISTRY_ABI,
  CATALOG_ABI,
  TREASURY_ABI,
} from '@pyrimid/sdk';typescript

Exported types

import type {
  PyrimidProduct,     // Product listing
  PurchaseResult,     // Purchase receipt
  PaymentSplit,       // Commission breakdown
  AffiliateStats,     // Affiliate performance
  VendorStats,        // Vendor analytics
  ProtocolStats,      // Network-wide stats
  CatalogResponse,    // API response shape
  CatalogQueryParams, // Query parameters
  ResolverConfig,     // Resolver constructor
  McpServerConfig,    // MCP server factory
  VendorMiddlewareConfig, // Middleware setup
  PaymentReceipt,     // Payment verification
} from '@pyrimid/sdk';typescript

API Reference

Base URL: https://api.pyrimid.ai

GET /v1/catalog

Aggregated product catalog from all sources (onchain, Bazaar, MCPize, MCP Hive, Apify).

GET https://api.pyrimid.ai/v1/catalog
ParameterTypeDefaultDescription
querystringKeyword search across descriptions, tags, categories
categorystringFilter by category
max_pricenumberMax price in USD
verified_onlybooleanfalseOnly ERC-8004 verified vendors
limitnumber50Results per page (max 200)
offsetnumber0Pagination offset
sortstringrelevancerelevance, price_asc, price_desc, volume, newest
// Response
{
  "products": [
    {
      "vendor_id": "vn_trading_brain",
      "vendor_name": "Trading Brain",
      "vendor_erc8004": true,
      "product_id": "signals_latest",
      "description": "BTC perpetual futures trading signal",
      "price_usdc": 250000,
      "price_display": "$0.25",
      "affiliate_bps": 2000,
      "source": "onchain",
      "sdk_integrated": true
    }
  ],
  "total": 347,
  "sources": { "onchain": 12, "bazaar": 251, "mcpize": 84 }
}json

GET /v1/stats

Protocol-level or entity-specific statistics.

GET https://api.pyrimid.ai/v1/stats
ParameterTypeDefaultDescription
typestringprotocolprotocol, affiliate, vendor
idstringEntity ID (required for affiliate/vendor)
// GET /v1/stats?type=protocol
{
  "protocol": {
    "total_volume_usdc": 5420000000,
    "total_volume_display": "$5.4K",
    "total_transactions": 847,
    "total_affiliates": 23,
    "total_vendors": 5,
    "treasury_balance_usdc": 54200000
  },
  "catalog": { "total_products": 347 },
  "recent_transactions": [...]
}json
// GET /v1/stats?type=affiliate&id=af_xxx
{
  "affiliate": {
    "reputation_score": 4200,
    "total_earnings_display": "$127.50",
    "sales_count": 89,
    "unique_buyers": 34,
    "erc8004_linked": true
  },
  "recent_sales": [...]
}json
// GET /v1/stats?type=vendor&id=vn_xxx
{
  "vendor": {
    "total_volume_display": "$2.1K",
    "total_sales": 312,
    "unique_affiliates": 8,
    "affiliate_payouts_usdc": 420000000
  },
  "recent_sales": [...]
}json

Contracts

Four contracts on Base mainnet. Forked from Fluencr with major simplifications — Gold tier removed, multi-stablecoin reduced to USDC-only, vendor self-service added, ERC-8004 integration added.

ContractAddressRole
PyrimidRegistry 0x2263852363Bce16791A059c6F6fBb590f0b98c89 Affiliate + vendor registration, ERC-8004, reputation
PyrimidCatalog 0x1ae8EbbFf7c5A15a155c9bcF9fF7984e7C8e0E74 Product listings, pricing, commission rates
PyrimidRouter 0x6594A6B2785b1f8505b291bDc50E017b5599aFC8 Commission splitting engine
PyrimidTreasury 0xdF29F94EA8053cC0cb1567D0A8Ac8dd3d1E00908 Protocol operations fund (1% accumulator)
External dependencies

USDC on Base: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
ERC-8004 Identity Registry: 0x8004A169FB4a3325136EB29fA0ceB6D2e539a432

Commission Split

Every transaction splits automatically in a single onchain call through the PyrimidRouter.

Example: $0.25 signal, 20% affiliate commission
Protocol
$0.0025 1%
Affiliate
$0.0495 19.8%
Vendor
$0.1980 79.2%
import { calculateSplit } from '@pyrimid/sdk';

const split = calculateSplit(250_000, 2000); // $0.25, 20% affiliate
// { total_usdc: 250000, protocol_fee: 2500,
//   affiliate_commission: 49500, vendor_share: 198000 }typescript
Commission range

Enforced by contract: minimum 500 bps (5%), maximum 5000 bps (50%). Vendors set per-product. No affiliate attributed → vendor gets 99%.

Reputation System

Onchain score (0–10,000) updated on every sale. Higher reputation = better catalog placement = better commission offers from vendors.

FactorPointsMax
Sales count30 per sale3,000
Unique buyers50 per buyer2,500
Vendor diversity300 per vendor served1,500
ERC-8004 verifiedFlat bonus2,000
Volume bonus1 per $10 volume1,000

ERC-8004 Identity

Optional but strongly incentivized. Link your ERC-8004 agent identity for +2,000 reputation, priority catalog placement, and composable identity across the agent ecosystem.

// Link via contract call
registry.linkERC8004Identity(agentId);

// Or via MCP tool
// pyrimid_register_affiliate({ wallet_address, ... })typescript

Roadmap: Optional at launch → increasingly advantageous → eventually required for affiliate registration.

Specification

The full Pyrimid v0.2 master specification covers architecture, contract design, SDK, distribution model, revenue projections, anti-gaming, and go-to-market strategy.

Attached files

pyrimid-spec-v0.2.md — Master specification (single source of truth)
pyrimid-sdk-mcp-server.ts — MCP server factory source
pyrimid-sdk-resolver.ts — PyrimidResolver source

SDK Source

Package structure for @pyrimid/sdk:

@pyrimid/sdk/
├── package.json
├── tsconfig.json
├── README.md
└── src/
    ├── index.ts          ← barrel export
    ├── types.ts         ← addresses, ABIs, interfaces
    ├── resolver.ts      ← PyrimidResolver class
    ├── mcp-server.ts    ← createPyrimidMcpServer()
    └── middleware.ts    ← pyrimidMiddleware + withPyrimid
Copied