@piprail/sdk
v2.0.0
Published
Accept x402 crypto payments across 29 chains — every major EVM chain plus Solana, TON, Tron, NEAR, Sui, Aptos, Algorand, Stellar & XRPL — in a couple of lines. No backend, no database, no fee; payments settle straight to your wallet.
Maintainers
Readme
@piprail/sdk
Accept and make x402 crypto payments — on any EVM chain plus Solana, TON, Tron, NEAR, Sui, Aptos, Algorand, Stellar & the XRP Ledger — in a couple of lines.
No middleman, no database, no fee, no account. Payments settle straight into your wallet, verified locally against your own RPC. Gate a route to make it paid-only; point an agent at a paid URL and it pays itself.
npm install @piprail/sdk viem📖 Full documentation → docs.piprail.com
The docs are the single, searchable source of truth — every function, option, chain, and example, plus the MCP server, spend controls, discovery, and the complete error model. This README is just the front door.
Charge for an endpoint
import { requirePayment } from '@piprail/sdk'
app.get('/report',
requirePayment({ chain: 'base', token: 'USDC', amount: '0.05', payTo: '0xYourWallet…' }),
(_req, res) => res.json({ report: 'TOP SECRET' }),
)That route now costs 0.05 USDC on Base, paid straight to your wallet. One parameter picks the chain. → Accepting payments
Let an agent pay for it
import { PipRailClient } from '@piprail/sdk'
const client = new PipRailClient({ chain: 'base', wallet: { key: process.env.AGENT_KEY } })
const res = await client.fetch('https://api.example.com/report') // hits the 402, pays it, retries with proofPay across chains — one buyer, a wallet per chain
A client is bound to one chain (an EVM key can't sign a Solana tx). To pay a 402
on whatever chain it asks for, give a MultiChainPayer one wallet per chain —
it surveys every chain you hold and pays the first one you listed that can settle
(your preference; within a chain, the cheapest-gas rail — there's no oracle to compare
gas across coins):
import { MultiChainPayer } from '@piprail/sdk'
const payer = MultiChainPayer.fromWallets({
wallets: {
base: { key: process.env.EVM_KEY }, // one EVM key works on every EVM chain
solana: { key: process.env.SOLANA_KEY },
xrpl: { key: process.env.XRPL_SEED },
},
policy: { maxAmount: '1.00', maxTotal: '10.00', tokens: ['USDC', 'USDT'] }, // one budget, every chain
})
await payer.planPayment(url) // read-only: every chain ranked, payable-first in your listed order
const res = await payer.get(url) // pays on the first chain that can settle — same spend policy, no manual routingBuilt on planAcross / fetchAcross (the same composable primitives, for when you
already hold an array of clients). See examples/multi-chain.
The same app can take payments and make them. → Making payments
Documentation
| | |
|---|---|
| Getting started | Install · quickstart · how it works |
| Accepting payments | requirePayment · createPaymentGate · the exact rail |
| Making payments | PipRailClient · quote · estimateCost · planPayment · auto-route · MultiChainPayer |
| Spend controls | Budgets · time envelope · the spend ledger |
| Agent toolkit | paymentTools · the agent guide · NL renderers |
| Discovery | Find & be found on the open x402 indexes ($0, no backend) |
| Chains & tokens | Every chain, per-family setup & caveats |
| Errors | The complete typed error model |
| MCP server | Give any AI agent a budget-bound wallet |
| Reference | The complete API surface |
Spread the word
PipRail is free, open-source, and has no backend to sell you. If it saved you from building a payments backend, help other developers (and their agents) find it:
⭐ Star on GitHub · 𝕏 Follow @piprailhq · 🌐 piprail.com · 📖 docs.piprail.com
License & trademark
The code is MIT — use it, fork it, ship it. PipRail™, the logo, and the @piprail npm scope are trademarks of the PipRail project: build on the code freely, but please don't call a fork "PipRail" or imply it's official. See TRADEMARK.md.
