Skip to main content

Quickstart

1) Install

npm install @pepaylabs/bnbpay ethers

2) Resolve network config

import { createApiClient } from '@pepaylabs/bnbpay';

const api = createApiClient();
const { networks } = await api.networks();
const bnb = networks.find((n) => n.key === 'bnb');
if (!bnb) throw new Error('BNB network not configured');

3) Build a PaymentIntent

import { createFlexIntent } from '@pepaylabs/bnbpay';
import { ethers } from 'ethers';

const intent = createFlexIntent({
merchant: '0xMerchant',
token: ethers.ZeroAddress,
amount: ethers.parseEther('0.25'),
chainId: bnb.chainId,
referenceId: 'order-1001',
scheme: 'push:evm:direct',
});

// Persist intent.intent.nonce; it's required for paymentId binding.

4) Send the payment through the router

import { sendRouterPayment, RpcTransport } from '@pepaylabs/bnbpay';

await sendRouterPayment({
transport: new RpcTransport(signer),
routerAddress: bnb.router,
intent: intent.intent,
witness: intent.witness,
reference: intent.referenceId,
});

5) Verify settlement

const payment = await api.payments.get(intent.paymentId);
console.log('settled', payment.paymentId, payment.resourceId);

Optional: Invoice flow (API + relay)

import { createApiClient } from '@pepaylabs/bnbpay';

const api = createApiClient({ apiKey: process.env.BNBPAY_RELAY_KEY });
const invoice = await api.invoices.create({
title: 'Order #1002',
merchantId: 'store-123',
amount: '25.00',
currencyToken: 'USDT',
network: 'bnb',
tokenAllowlist: ['0x55d398326f99059fF775485246999027B3197955'],
});

const intentPayload = await api.payments.buildIntent({
mode: 'minimal',
network: 'bnb',
merchant: '0xMerchant',
token: '0x55d398326f99059fF775485246999027B3197955',
amount: '25.00',
scheme: 'permit2',
invoiceId: invoice.invoiceId,
});

// Build witness (see Payments → Flows for details), sign witness + permit,
// then relay the signed payload:
await api.relay.payment({
network: 'bnb',
scheme: 'permit2',
intent: intentPayload.derived.intent,
witness,
witnessSignature,
permit2,
reference: intentPayload.input.baseReference,
});

This flow keeps invoices, payment intents, and relay execution aligned with the API source of truth.