@billmyagent/payments-core
v2.1.3
Published
x402 payment client for billmyagent — auto-pays HTTP 402 challenges with a viem signer (EIP-3009) and manages merchant payments/fees
Readme
@billmyagent/payments-core
x402 payment client for billmyagent. It pays
HTTP 402 Payment Required challenges automatically using the official
x402 libraries: it signs an EIP-3009
transferWithAuthorization with your wallet and lets the facilitator settle it
on-chain. Framework-agnostic — wrap it with
@billmyagent/payments-react, -vue, or -elements.
Install
npm install @billmyagent/payments-corePay an x402-gated API
import { PaymentClient, createSigner } from '@billmyagent/payments-core';
// Build a signer from a private key (server/agent). Never ship a real key to a browser.
const signer = await createSigner('base', process.env.PRIVATE_KEY!);
const client = new PaymentClient({ signer });
// `client.http` is an axios instance; any 402 it hits is paid and the request retried.
const res = await client.http.get('https://api.example.com/paid-resource');
console.log(res.data);In a browser, pass a viem wallet client backed by the user's wallet instead of a private-key signer.
Merchant account methods
Pass an apiKey (and authToken JWT for /merchant/*) to use the billmyagent
REST API:
const client = new PaymentClient({ apiKey: process.env.BMA_API_KEY!, authToken: jwt });
await client.getPayoutSettings();
await client.updatePayoutSettings({ base_address: '0x…' });
await client.getFees();
await client.listInvoices();Also available: createPayment, getPayment, verifyPayment, settlePayment,
listPayments.
What's in the box
PaymentClient— pays x402 challenges (client.http) and wraps the merchant REST APIcreateSigner/Signer— re-exported fromx402-axiosfor building wallet signers- Types:
Payment,CreatePaymentRequest,PayoutSettings,FeeRow,FeeInvoice, and the re-exportedAxiosRequestConfig/AxiosResponse
Supported networks
EVM only, exact scheme: Base, Ethereum, Polygon.
Development
# from sdk/core/
npm install
npm run buildLicense
Apache 2.0 — see LICENSE.
