Book a free call

How to Build a dApp on BSC, Step by Step

Build a dApp on BNB Smart Chain with Solidity, Hardhat and a wallet-connected frontend. This guide covers setup, the 7-step build, testing and mainnet launch.

Hertiv engineering teamReviewed by a senior engineer
8 min read
How to Build a dApp on BSC, Step by Step
On this page

Short answer

To build a dApp on BSC, write the core logic as a Solidity smart contract, test it with Hardhat, deploy it to the BSC testnet (chain ID 97), verify it on BscScan, then connect a wallet-based frontend with wagmi or viem. BSC is EVM-compatible, so Ethereum tooling works, gas is paid in BNB, and blocks arrive about every 3 seconds.

What is a dApp on BSC?

A dApp on BSC is an application whose core logic runs in smart contracts on BNB Smart Chain while the user interface runs in a normal web app. The contract holds the state and the rules, and the frontend reads from it and sends transactions to it.

BSC is the EVM-compatible smart contract chain of the BNB Chain ecosystem. Because it runs the same virtual machine as Ethereum, contracts written in Solidity work on BSC without changes, and the same tools work too: Hardhat, Remix, ethers.js, viem and MetaMask.

A typical BSC dApp has four parts. The smart contract stores balances, ownership or votes on chain. The frontend is a web page that connects a wallet and calls the contract. An indexer or event listener keeps the interface fast by reading contract events. A wallet such as MetaMask signs each transaction.

What makes a dApp different from a normal app is that no single server controls the core logic. Once the contract is deployed, its rules run the same way for every user, and anyone can check the code and the on-chain history on BscScan.

Why build your dApp on BSC?

Teams build on BSC when they want Ethereum-style tooling with faster blocks and lower gas costs. BSC produces a block about every 3 seconds, and gas is paid in BNB, which keeps each transaction cheap enough for everyday use.

The main trade-off is decentralisation. BSC uses Proof of Staked Authority with 21 validators, so it is far more centralised than Ethereum. For a consumer app, a game or a payments flow, that trade is often acceptable; for a protocol that must resist censorship, it may not be.

PointBSCEthereum
Block timeAbout 3 secondsAbout 12 seconds
Gas tokenBNBETH
Mainnet chain ID561
Testnet chain ID97 (Chapel)11155111 (Sepolia)
Contract languageSoliditySolidity
Validators21Hundreds of thousands

BSC also sits inside a wider ecosystem. If your dApp outgrows the main chain, opBNB is a layer 2 built on the Optimism OP Stack for high-frequency use, and BNB Greenfield offers decentralised storage for files and data that should not live on chain. You can start on BSC and add those layers later. For a side-by-side view, the BSC vs Ethereum comparison for dApp development covers fees, speed and tooling in detail.

What do you need before you start?

Before you write any code, gather the tools and accounts a BSC dApp needs. Most of them are free, and the same stack works for a first prototype and for a production launch.

PartToolWhat it does
WalletMetaMaskHolds test BNB and signs transactions
Test networkBSC testnet (chain ID 97)Free practice chain with test BNB from a faucet
ContractsHardhat or RemixWrite, compile and deploy Solidity contracts
Contract librariesOpenZeppelin ContractsAudited building blocks for tokens and access control
FrontendReact with wagmi or viemConnect wallets and call contracts from the browser
ExplorerBscScanCheck transactions and verify contract source code

Add the BSC testnet to MetaMask first, using chain ID 97 and the public testnet RPC endpoint, then get test BNB from the official BSC faucet. Test BNB has no value, so you can deploy, break and redeploy as often as you like.

Decide the scope of the first version before you build. A dApp that does one thing well, such as tipping, voting or simple swaps, is easier to test and audit than a platform with five features. Write down the contract functions, the events the frontend needs, and who is allowed to call each function.

How do you build a dApp on BSC in 7 steps?

You build a BSC dApp by writing the contract first, testing it on the testnet, and only then connecting a frontend. Each step below has a clear check before you move on.

  1. Define the contract. List the state the contract holds, the functions users call, and the events it emits. Keep the first version small.
  2. Write the contract in Solidity. Use OpenZeppelin Contracts for standard parts such as ownership, access control and token behaviour instead of writing them from scratch.
  3. Compile and test locally. Run unit tests in Hardhat against a local chain. Test the failure paths too, not just the happy path.
  4. Deploy to the BSC testnet. Deploy with Hardhat to chain ID 97, using test BNB. Check the deployment on the testnet BscScan explorer.
  5. Verify the source code. Verify the contract on BscScan so anyone can read it. Unverified contracts are a warning sign for users.
  6. Build the frontend. Connect a wallet with wagmi or viem, read contract state for display, and send transactions through the wallet. Show the transaction status after each action.
  7. Test with real users, then audit. Run a small closed test on the testnet, fix what breaks, get a security review, and only then deploy to mainnet with chain ID 56.

Keep the contract and the frontend in separate folders in one repository so a change to one does not silently break the other. Record the deployed contract address and the chain ID in the frontend configuration, never hard-coded in two places.

How do wallets and the frontend connect to BSC?

The frontend connects to BSC through the user's wallet. When a user opens the dApp, the page asks the wallet to connect, checks which chain it is on, and asks it to switch to BSC if needed.

Use a library such as wagmi or viem rather than writing wallet code by hand. These libraries handle connection, chain switching, reading contract state and sending transactions, and they work with MetaMask and with WalletConnect for mobile wallets.

Reads are free and need no signature. The frontend calls view functions on the contract through an RPC endpoint to show balances, prices or votes. Writes cost gas and need a signature, so the frontend should show the estimated fee and wait for the transaction receipt before updating the screen.

Set the chain ID explicitly in your configuration: 56 for mainnet and 97 for the testnet. A wrong chain ID is one of the most common reasons a dApp appears broken, because the wallet is connected to a different network and the contract address does not exist there. For the contract side, the steps in how to create a smart contract on BSC cover the Remix and deployment flow in detail.

How do you test and deploy to BSC mainnet?

You test a BSC dApp in three layers: unit tests for the contract, a full run on the testnet, and a small closed test with real users. Only after all three pass should you deploy to mainnet.

Unit tests in Hardhat should cover every function, including the ones that should fail. A function that lets anyone withdraw funds is a bug that a single test would have caught. Aim for tests that check balances before and after each call, and that confirm the right events are emitted.

On the testnet, run the complete user journey from the frontend: connect a wallet, perform each action, and confirm the on-chain result on BscScan. Test with more than one wallet, and test what happens when a transaction fails or the user rejects it in the wallet.

Before mainnet, get a security review. An audit does not guarantee safety, but a reviewer will catch issues such as reentrancy, missing access checks and unsafe arithmetic that are easy to miss in your own code.

Deploy to mainnet with a small amount of value first, watch the first transactions, and keep an upgrade or pause plan ready. If your dApp issues its own token, read token development on Binance Smart Chain before you design the supply and distribution.

Example (hypothetical): a small tipping dApp on BSC

Example (hypothetical): a team builds a tipping dApp where readers tip writers in BNB. The contract holds tips, records the writer for each tip, and lets a writer withdraw the balance. The frontend shows each writer's total tips.

The team deploys to the testnet first. During a closed test, 40 readers send tips of 0.02 BNB each, so the contract holds 40 x 0.02 = 0.8 BNB. One writer receives 25 of those tips, which is 25 x 0.02 = 0.5 BNB, and the other 15 tips, worth 0.3 BNB, go to a second writer.

Each tip costs about 0.0005 BNB in gas on the testnet. The 40 tips together cost 40 x 0.0005 = 0.02 BNB in fees, which is small next to the 0.8 BNB tipped. On mainnet the team expects similar costs, so a tip of 0.02 BNB still leaves the writer with almost the full amount.

The first writer withdraws 0.5 BNB. The contract balance falls from 0.8 BNB to 0.3 BNB, which matches the second writer's tips exactly. That check, done on BscScan, confirms the contract accounting is correct before the team opens the dApp to the public.

What are the common mistakes?

The most common BSC dApp mistakes are deploying untested contracts, hard-coding the wrong chain, and trusting the frontend to enforce rules that only the contract can enforce.

  • Skipping the testnet. Deploying straight to mainnet turns every bug into a real loss. Test on chain ID 97 first.
  • Wrong chain ID. A frontend pointed at chain 56 while the wallet is on chain 97 will fail silently. Set the chain ID in one place and check it.
  • Rules only in the frontend. Anything the frontend blocks can be bypassed by calling the contract directly. Put every rule in the contract.
  • Unverified contracts. Users cannot check what an unverified contract does. Verify the source on BscScan after every deploy.
  • No pause or upgrade plan. A bug found after launch needs a response. Decide before launch who can pause the contract and how.
  • Ignoring gas costs. A function that loops over a growing list gets more expensive with every user. Keep loops short or move the work off chain.

Key takeaways

  • BSC is EVM-compatible, so Solidity, Hardhat, Remix and MetaMask work as they do on Ethereum
  • Use chain ID 56 for mainnet and 97 for the testnet, and set it in one place in your code
  • Write the contract first, test it on the testnet, verify it on BscScan, then build the frontend
  • Enforce every rule in the contract, because the frontend alone cannot stop a direct contract call
  • Get a security review before mainnet and deploy with a small amount of value first

Frequently asked questions

Do I need to learn a new language to build on BSC?

No. BSC is EVM-compatible, so you write contracts in Solidity and use the same tools as on Ethereum, including Hardhat, Remix, ethers.js and viem. The main differences are the network settings: chain ID 56 for mainnet, 97 for the testnet, and BNB as the gas token.

How much does it cost to deploy a dApp on BSC?

Deployment costs depend on the size of the contract, because larger contracts use more gas. BSC gas fees are generally low compared with Ethereum mainnet, and testing on the testnet is free because test BNB comes from a faucet. Check the current fee on BscScan before you deploy.

What is the difference between BSC and opBNB?

BSC is the main smart contract chain of the BNB Chain ecosystem. opBNB is a layer 2 built on the Optimism OP Stack that settles on BSC and handles higher transaction volumes at lower cost. Most dApps start on BSC and only move high-frequency activity to opBNB when they need it.

Can I use MetaMask with a BSC dApp?

Yes. MetaMask supports BSC once you add the network with the right chain ID and RPC endpoint, or connect through a library such as wagmi that handles the network switch. Users then sign transactions with BNB for gas, and the dApp reads contract state through the same connection.

Why should I verify my contract on BscScan?

Verification publishes the source code next to the deployed contract, so anyone can read what it does and check it against what you claim. Unverified contracts are a warning sign for users and auditors, and many wallets and tools treat them with suspicion. Verify after every deploy.

What should I do if a bug is found after launch?

Pause the contract if it has a pause function, warn users, and fix the issue in a new deployment or through the upgrade path you planned. This is why a pause plan and an upgrade plan matter before launch. Never try to fix a live contract by asking users to trust an unverified replacement.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: blockchain systems in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Planning a dApp on BSC? Talk to Hertiv.

A senior engineer replies within one business day. Or see our dApp Development service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to contact@hertiv.com.

Prefer email? Write to contact@hertiv.com
Estimate costBook a call