Summary
This page explains how to connect to the BNB Chain Testnet (BSC Testnet) using an RPC endpoint. You'll find the official OnFinality public endpoint, chain settings, faucet instructions, and common debugging tips for building and testing dApps on testnet.
Quick Start: Connect to BNB Chain Testnet
If you're building on BNB Chain (formerly BSC) and need a testnet environment, the BNB Chain Testnet (chain ID 97) is the place to start. This guide gives you the exact RPC endpoint, chain settings, and debugging tips to get your dApp running quickly.
OnFinality public endpoint: https://bnb-testnet.api.onfinality.io/public
This endpoint is free to use for development and light testing. For production workloads or higher rate limits, consider a dedicated node or a managed RPC plan.
Chain Settings at a Glance
Before you connect, make sure your wallet or dApp uses the correct network parameters. Here's a quick reference table:
| Parameter | Value |
|---|---|
| Network Name | BNB Smart Chain Testnet |
| Chain ID | 97 |
| Native Currency | tBNB (BNB Chain Native Token) |
| Symbol | tBNB |
| Decimals | 18 |
| Block Explorer | https://testnet.bscscan.com |
| RPC Endpoint | https://bnb-testnet.api.onfinality.io/public |
Adding BNB Testnet to Your Wallet
Most developers add the testnet to MetaMask or another wallet to interact with their dApp. Here's a common configuration snippet you can use:
{
"chainId": "0x61",
"chainName": "BNB Smart Chain Testnet",
"nativeCurrency": {
"name": "BNB Chain Native Token",
"symbol": "tBNB",
"decimals": 18
},
"rpcUrls": ["https://bnb-testnet.api.onfinality.io/public"],
"blockExplorerUrls": ["https://testnet.bscscan.com"]
}
You can add this via MetaMask's "Add Network" flow or programmatically using wallet_addEthereumChain.
Getting Testnet BNB from the Faucet
To pay for gas on the testnet, you need tBNB. The official BNB Chain faucet is the primary source. Visit the BNB Chain faucet and connect your wallet. You'll receive a small amount of tBNB, usually enough for a few transactions. If you need more, you can request again after a cooldown period.
Making Your First JSON-RPC Call
Once you have the endpoint, you can test connectivity with a simple eth_chainId call. Here's a curl example:
curl -X POST https://bnb-testnet.api.onfinality.io/public \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}'
Expected response:
{"jsonrpc":"2.0","id":1,"result":"0x61"}
The 0x61 is the hexadecimal representation of chain ID 97.
Using ethers.js or viem
If you're using a JavaScript library, here's how to connect with ethers.js:
const { ethers } = require("ethers");
const provider = new ethers.JsonRpcProvider("https://bnb-testnet.api.onfinality.io/public");
async function getBlockNumber() {
const blockNumber = await provider.getBlockNumber();
console.log("Current block:", blockNumber);
}
getBlockNumber();
And with viem:
import { createPublicClient, http } from 'viem';
import { bscTestnet } from 'viem/chains';
const client = createPublicClient({
chain: bscTestnet,
transport: http('https://bnb-testnet.api.onfinality.io/public')
});
const blockNumber = await client.getBlockNumber();
console.log("Current block:", blockNumber);
Debugging Common Issues
Even with the right endpoint, you might run into issues. Here's a quick troubleshooting table:
| Symptom | Likely Cause | Fix |
|---|---|---|
eth_chainId returns wrong value | Wrong network selected | Check chain ID is 97 |
| Transaction stuck or dropped | Insufficient tBNB for gas | Get more from the faucet |
nonce too low error | Transaction replay or stale nonce | Reset account activity in wallet |
| Connection timeouts | Public endpoint rate limit | Use a dedicated node or API key |
| Contract call reverts | Contract not deployed on testnet | Verify contract address on explorer |
Public vs. Dedicated RPC for Testnet
For simple testing, the public endpoint is sufficient. But if you're running automated tests, load testing, or a CI/CD pipeline, you might hit rate limits. In that case, consider a dedicated node or a managed RPC plan that offers higher throughput and more reliability.
OnFinality provides both shared and dedicated infrastructure for BNB Chain Testnet. You can check the network page for details and to get an API key.
Key Takeaways
- The BNB Chain Testnet RPC endpoint is
https://bnb-testnet.api.onfinality.io/public. - Chain ID is 97, and the native currency is tBNB.
- Use the official faucet to get testnet BNB.
- Test your connection with
eth_chainIdbefore building. - For production-grade testing, consider a dedicated node or managed RPC service.
Frequently Asked Questions
What is the BNB Chain Testnet RPC URL?
The public RPC URL is https://bnb-testnet.api.onfinality.io/public. You can also get a dedicated endpoint from OnFinality.
How do I get testnet BNB?
Use the official BNB Chain faucet at https://www.bnbchain.org/en/testnet-faucet.
What is the chain ID for BNB Testnet?
The chain ID is 97.
Can I use the same RPC for mainnet?
No, mainnet uses a different endpoint and chain ID (56). See the BNB Chain mainnet page for details.
Is the public endpoint rate-limited?
Public endpoints may have rate limits. For higher limits, consider a dedicated node or RPC pricing.