npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

b402-sdk

v1.0.1

Published

Accept crypto payments with zero gas fees on BSC - USD1, USDT, USDC

Readme

b402-sdk

Accept crypto payments on Binance Smart Chain with zero gas fees for users.

Installation

npm install b402-sdk ethers@6

Quick Start

import { B402 } from 'b402-sdk';
import { Wallet } from 'ethers';

// User's wallet
const wallet = new Wallet(process.env.PRIVATE_KEY!);

// Create B402 client
const b402 = new B402('mainnet');

// Send payment (user pays ZERO gas!)
const result = await b402.pay(wallet, {
  amount: '0.01',        // Amount in human-readable format
  token: 'USD1',         // USD1, USDT, or USDC
  recipient: '0x...'     // Seller's wallet address
});

if (result.success) {
  console.log('Payment sent!', result.txHash);
  // View on BSCScan: https://bscscan.com/tx/${result.txHash}
}

How It Works

  1. User signs payment authorization with MetaMask (EIP-712) - FREE
  2. B402 facilitator validates signature
  3. Facilitator submits transaction on-chain and pays gas (~$0.003)
  4. Payment settles in <3 seconds

User pays ZERO gas fees.

Supported Tokens

Mainnet (BSC)

  • USD1 - World Liberty Financial stablecoin
  • USDT - Tether USD
  • USDC - USD Coin

Testnet (BSC Testnet)

  • USDT - Testnet USDT

Before First Payment

Users need to approve the B402 relayer contract once:

import { Contract } from 'ethers';

const usd1 = new Contract(
  '0x8d0d000ee44948fc98c9b98a4fa4921476f08b0d',  // USD1 on BSC
  ['function approve(address spender, uint256 amount)'],
  wallet
);

await usd1.approve(
  '0xE1C2830d5DDd6B49E9c46EbE03a98Cb44CD8eA5a',  // B402 Relayer
  '115792089237316195423570985008687907853269984665640564039457584007913129639935'  // Max approval
);

After this one-time approval, all future payments are instant and gasless!

API Reference

new B402(network?, facilitatorUrl?)

Create B402 client.

  • network: 'mainnet' or 'testnet' (default: 'mainnet')
  • facilitatorUrl: Custom facilitator URL (optional)

b402.pay(wallet, options)

Send payment.

Parameters:

  • wallet: ethers.js Wallet object
  • options.amount: Amount as string (e.g., '0.01')
  • options.token: 'USD1' | 'USDT' | 'USDC'
  • options.recipient: Seller's wallet address
  • options.timeoutSeconds: Payment validity period (default: 3600)

Returns:

{
  success: boolean;
  txHash?: string;
  error?: string;
  payer: string;
  recipient: string;
  amount: string;
  token: string;
}

Example: Complete Payment Flow

import { B402 } from 'b402-sdk';
import { Wallet, Contract, JsonRpcProvider } from 'ethers';

async function sendPayment() {
  // Setup
  const provider = new JsonRpcProvider('https://bsc-dataseed1.binance.org');
  const wallet = new Wallet(process.env.PRIVATE_KEY!, provider);
  
  // Check USD1 balance
  const usd1 = new Contract(
    '0x8d0d000ee44948fc98c9b98a4fa4921476f08b0d',
    ['function balanceOf(address) view returns (uint256)',
     'function allowance(address,address) view returns (uint256)',
     'function approve(address,uint256) returns (bool)'],
    wallet
  );
  
  const balance = await usd1.balanceOf(wallet.address);
  console.log('Balance:', balance.toString());
  
  // Check/approve relayer
  const allowance = await usd1.allowance(
    wallet.address,
    '0xE1C2830d5DDd6B49E9c46EbE03a98Cb44CD8eA5a'
  );
  
  if (allowance === 0n) {
    console.log('Approving relayer...');
    const tx = await usd1.approve(
      '0xE1C2830d5DDd6B49E9c46EbE03a98Cb44CD8eA5a',
      '115792089237316195423570985008687907853269984665640564039457584007913129639935'
    );
    await tx.wait();
    console.log('Approved!');
  }
  
  // Send payment
  const b402 = new B402('mainnet');
  const result = await b402.pay(wallet, {
    amount: '0.01',
    token: 'USD1',
    recipient: '0x96625c0e209b4e0d4741d8a3ffb6b91c0da6fa5f'
  });
  
  if (result.success) {
    console.log('Payment successful!');
    console.log('TX:', result.txHash);
    console.log('View on BSCScan: https://bscscan.com/tx/' + result.txHash);
  } else {
    console.error('Payment failed:', result.error);
  }
}

sendPayment();

Live Example

Check out this real transaction on BSC mainnet: https://bscscan.com/tx/0x665845a92fd09e4673dac65ae23725cd58d2350d0347d2fca921bbe4a96eab30

  • User paid: $0.00 gas
  • Facilitator paid: $0.003 gas
  • Payment: 0.01 USD1 transferred instantly

Security

  • EIP-712 signatures - Industry standard (Uniswap, OpenSea)
  • Nonce system - Prevents replay attacks
  • Time-bounded - Authorizations expire
  • On-chain verification - Contract verifies signatures before transfer

Network Details

Mainnet

  • Chain ID: 56
  • RPC: https://bsc-dataseed1.binance.org
  • B402 Relayer: 0xE1C2830d5DDd6B49E9c46EbE03a98Cb44CD8eA5a
  • USD1: 0x8d0d000ee44948fc98c9b98a4fa4921476f08b0d
  • USDT: 0x55d398326f99059fF775485246999027B3197955
  • USDC: 0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d

Testnet

  • Chain ID: 97
  • RPC: https://data-seed-prebsc-1-s1.binance.org:8545
  • B402 Relayer: 0x62150F2c3A29fDA8bCf22c0F22Eb17270FCBb78A
  • USDT: 0x337610d27c682E347C9cD60BD4b3b107C9d34dDd

License

MIT

Links

  • Homepage: https://b402.ai
  • GitHub: https://github.com/vistara-labs/b402-protocol
  • NPM: https://npmjs.com/package/b402-sdk