Complete BNB BSC Payment Gateway: From Address Generation to Auto-Sweep
You're integrating a crypto payment gateway but aren't sure how to properly accept BNB on BNB Smart Chain (BSC). The task is non-trivial: generating unique addresses, monitoring transactions with confirmations, and auto-sweeping funds. We've implemented over 20 such integrations, from MVPs to high-load systems handling 10,000 transactions per day, with 5+ years of experience in blockchain infrastructure. BNB operates in two contexts: native BNB on BSC (chainId 56) and BEP‑2 BNB on the legacy Binance Chain. In 99% of cases, clients choose BSC — faster, cheaper, and supported by all popular wallets.
Why BSC and Not Binance Chain?
Binance Chain (BEP‑2) is a legacy chain with low throughput and no EVM compatibility. BSC provides access to the DeFi ecosystem, stablecoins, and ready-made monitoring tools. The average fee on BSC is ~$0.03 at 3 gwei and 21000 gas, which is tens of times cheaper than Ethereum. Additionally, most users store BNB on BSC. By choosing BSC, you reduce transaction costs by up to 60% compared to Ethereum.
Choosing an RPC Strategy: Node vs API
| Approach | Reliability | Cost | Complexity |
|---|---|---|---|
| Own BSC node | High (full control) | Free (own hosting) or $50/month VPS | Medium |
| Public RPC (Binance) | Medium (5000 requests/day) | Free | Low |
| BscScan API | Low (dependency) | Free (5 req/s) | Minimal |
For commercial acceptance, we recommend a hybrid: your own node for polling and BscScan as a fallback. This provides fault tolerance and removes RPS limits. Our turnkey integration includes node setup within 1 day.
Generating Unique Addresses with an HD Wallet
The safest method is to generate deposit addresses from a master seed without storing the seed on the server. We use an xpub that cannot spend funds (standard BIP44 with derivation path m/44'/714'/0'/0/ for BSC):
import { ethers } from "ethers"; const provider = new ethers.JsonRpcProvider("https://bsc-dataseed1.binance.org/"); // From mnemonic — for development. In production — xpub without storing seed const masterWallet = ethers.Wallet.fromPhrase(process.env.MNEMONIC!); function getDepositAddress(orderId: number): string { return masterWallet.deriveChild(orderId).address; } async function waitForPayment(address: string, expectedAmount: bigint): Promise<string> { return new Promise((resolve) => { provider.on({ address }, (tx) => { if (tx.value >= expectedAmount) { resolve(tx.hash); } }); }); } Reliable Monitoring via Polling
WebSocket subscriptions on public RPCs often drop. We use polling by checking blocks every 3 seconds:
async function checkPayment( depositAddress: string, expectedWei: bigint, fromBlock: number ): Promise<boolean> { const currentBlock = await provider.getBlockNumber(); for (let block = fromBlock; block <= currentBlock; block++) { const blockData = await provider.getBlock(block, true); const incoming = blockData?.transactions.filter( (tx: any) => tx.to?.toLowerCase() === depositAddress.toLowerCase() && BigInt(tx.value) >= expectedWei ); if (incoming && incoming.length > 0) return true; } return false; } Confirmations: on BSC we wait at least 15 blocks for amounts up to $1000, and 30+ for larger amounts. Reorgs are rare (<0.1% of blocks), but your handler must be ready for rollbacks.
Accepting USDT/USDC on BEP‑20
Often you need to accept stablecoins on BSC. The USDT BEP-20 contract: 0x55d398326f99059fF775485246999027B3197955. Monitor via the Transfer event:
const USDT_BSC = "0x55d398326f99059fF775485246999027B3197955"; const transferInterface = new ethers.Interface([ "event Transfer(address indexed from, address indexed to, uint256 value)" ]); const filter = { address: USDT_BSC, topics: [ ethers.id("Transfer(address,address,address)"), null, ethers.zeroPadValue(depositAddress, 32) ], }; provider.on(filter, (log) => { const { from, to, value } = transferInterface.parseLog(log)!.args; console.log(`Received ${ethers.formatUnits(value, 18)} USDT from ${from}`); }); To verify a transaction without a server, use ethers.js in the browser: connect to MetaMask and call provider.getTransaction(txHash). This is handy for debugging.
How to Auto-Sweep Funds from Deposit Addresses?
- Set a sweep threshold: for example, when the balance of a deposit address exceeds 0.1 BNB (minus a gas reserve).
- Run a cron job that checks balances of all active addresses once per hour via
provider.getBalance(address). - For each address with a balance above the threshold, initiate a transfer transaction to the main wallet.
- Leave a gas reserve on each address: ~0.0005 BNB at 3 gwei (enough for 80,000 gas).
- After sending, wait for confirmation (15 blocks) and update the status.
Sweep speed: 3-5 blocks (15-25 seconds) at 3 gwei. Gas savings compared to individual transfers — up to 40%.
Table: Common Errors and Solutions
| Error | Consequence | Solution |
|---|---|---|
| Storing seed phrase on server | Compromise of all funds | Use xpub for address generation |
| Ignoring reorgs | Double accounting of payments | Process blocks with confirmations |
Missing isError filter |
Counting failed transactions | Check status on BscScan |
| No gas reserve | Auto-sweep fails | Leave 0.0005 BNB on each address |
What's Included in the Work
-
Architecture: HD wallet scheme selection, RPC strategy, reorg error handling. -
Address Generation: integration with your backend via REST API, webhook notifications. -
Monitoring: polling with 3-5 second interval, event filtering, logging. -
Auto-Sweep: cron job with gas control and retry logic (up to 3 attempts). -
Documentation: API description, deployment guide for Docker/K8s. -
Support: 1 month of incident management and minor adjustments. -
Cost Estimate: we provide a fixed price after assessing your project – typically $2,000–$5,000 depending on complexity.
Time Estimates
- Basic setup for native BNB: from 1 day.
- Adding BEP-20 tokens and auto-sweep: 1-2 more days.
- Integration into an existing backend: +1-3 days depending on architecture.
- Turnaround: typical project completed within 5 business days.
Get a free consultation for your project — we'll assess complexity and provide a timeline and cost estimate at no charge.
Additional Information
According to official BSC documentation, using your own RPC node is recommended when the load exceeds 1000 requests per day. Average hosting cost for a node ranges from $0 (on your own server) to $50/month on a VPS. Savings on fees from internal transfers can reach 60% for systems with frequent payouts. Our team has delivered 20+ similar integrations over 5 years, ensuring robust security and performance.
BSC official documentation
Order a crypto payment gateway implementation from scratch or an upgrade of an existing one — we guarantee stability and provide source code. Contact us to get started.







