BNB Chain Development Quick Reference Guide

Obsidian Labs
8 min readJun 21, 2021

--

About BNB Chain

BNB Chain is a sovereign smart contract blockchain delivering Ethereum Virtual Machine (EVM) compatible programmability. By introducing the Proof of Stake Authority (PoSA) consensus mechanism, BNB Chain has created an ecosystem that allows nodes, token holders, developers, and users to benefit from the blockchain.

This article is a quick start guide for BNB Chain developers, hoping to provide developers with help.

Get Your BNB Chain Wallet Ready

In the blockchain world, digital wallet is not the actual container for cryptocurrencies. Rather, it stores pairs of encryption keys that represent ownership at certain addresses. Each pair of keys stored in digital wallets consists of a public key that is needed to initiate transactions and a matching private key for transaction encryptions and decryptions. Therefore, ownership of keypairs confers full control of the cryptocurrencies at the address associated with the keypairs. In the development stage, we create randomized keypairs and a piece of address information through our digital wallet, with which we are able to receive from or send cryptocurrencies to others. And this is why we have to get our wallets ready for development.

We highly recommend using Browser Plugin Wallet or Wallet App to manage keypairs while developing on BNB Chain.

Browser Plugin Wallet

Browser plugin wallet is the most popular choice in blockchain development. It’s easy to set up, install and access the wallet in the browser. Besides that, since the majority of blockchain applications are web-based, a browser plugin wallet gives intuitive access to pretty much all Defi and NFT apps available on the market.

Wallet App

When a smart contract goes live, most of its users access it through a wallet app of their choice.

Preparing BNB Chain Development Environment

Start Development today with BNB Studio

BNB Studio is a powerful yet user-friendly graphic IDE platform, specially designed for BNB Chain. It supports running locally on the majority of OS, including macOS, Windows, and Linux, and also on web browsers. Compared with traditional Ethereum development toolkits like Remix and Ganache, BNB Studio streamlines environment preparation procedures and integrates essential tools for a complete development lifecycle, including a graphic code editor, project manager, keypair manager, block explorer, contract inspector, and network manager.

Develop locally with BNB Studio Desktop

BNB Studio Desktop is a great all-in-one IDE platform for BNB Chain developers at all levels. You may download the latest release of BNB Studio Desktop at its Github Repo. BNB Studio currently supports major OS including macOS, Linux, and Windows.

Installation

  • macOS: Double click to open BNB-Studio-x.x.x.dmg and drag the app into the Application folder.
  • Linux: Double click to open BNB-Studio-x.x.x.AppImage, Select Properties( => Permissions => Execute and tick Allow executing file as program option. Close the Properties window and double-click to open the application. Please note, that different Linux distributions might have different application installation procedures.
  • Windows: Double click to open BNB-Studio-x.x.x.exe

Preparing Prerequisites

Upon the first successful startup of BNB Studio, you’ll be directed to a welcome screen that shows a list of prerequisites for BNB Chain Development, including Docker, BNB Node, and Truffle.

  • BNB Studio relies on Docker to start BNB node and compile projects. If you haven’t had Docker on your machines yet, click on Install Docker to visit the official Docker website to download the latest release and install it.
  • BNB Chain Docker Hub stores Docker images for BNB Chain nodes, which BNB Studio relies on to run BNB Chain nodes.
  • BNB Chain Truffle is the truffle toolkit used by BNB Studio for project creation and compilation.

When all prerequisites are successfully installed and started on the local machine, a green Get Started button will replace the gray Skip button. Now go ahead and click to start your smart contract development!

Develop online with BNB Studio Web

BNB Studio also offers a web version for developers who wish to develop, compile and run BNB Chain smart contracts online. BNB Studio web inherits most functionalities of the Desktop version but no longer requires setting up dependencies on local machines. It’s the perfect choice for BNB Chain developers who wants to try out BNB Chain development without worrying about setting up BNB Chain dependencies locally. Visit bsc.ide.black to experience BNB Chain development on the cloud.

For more information and tutorials on BNB Studio, check out BNB Studio Github Page

Connecting to BNB Chain networks

BNB Chain primarily offers two networks, namely BNB Chain Mainnet and BNB Chain Testnet.

  • BNB Chain Testnet, is a test network for test purposes, where Testnet tokens can be faucet free of charge and therefore contains no monetary value.
  • BNB Chain Mainnet, is the main network for production applications. Users are interacting with smart contracts on the Mainnet and thus Mainnet tokens (BNB/BEP20) are actual cryptocurrencies.

BNB Studio has BNB Chain Mainnet and Testnet connections preconfigured in the application and you may easily switch between these two networks. In order to support smoother development on BNB Chain networks, BNB Studio comes with a set of built-in tools like Browser Wallet, Block Explorer, and Faucet Tool, covering the most popular tools among BNB Chain developers.

BNB Chain Block Explorer

BNB Chain offers block explorer apps for network and on-chain information inquiry, Click to access Testnet Explorer or Mainnet Explorer.

BNB Chain Data Solution

If you’re no longer satisfied with the chain’s speed in sync as a result of scalability limited by native nodes, StreamingFast offers an alternative streaming solution with full history for those who want to get real-time updates of contracts, account balances, AMM prices or sync their local database, with speed 50x faster than nodes. Available to everyone for free at StreamingFast.io

Faucet

Developers often need tokens when developing on BNB Chain Testnet to play with contracts or to make transactions. BNB Chain Testnet offers a Faucet service to acquire free Testnet tokens, of course, BNB Studio also integrates Faucet Functionality in the toolbar for the easier invocation of faucet tokens.

BNB Chain Smart Contract Development

Key Tools in BNB Chain Development

Truffle is a development framework based on Solidity that aims to simplify the construction and management process of dApp. Truffle is written in Javascript and comes with a powerful set of features to support the compilation, deployment, and test of smart contracts.

Solc is a command-line compiler for Solidity. It compiles smart contract code written in Solidity into binary code in EVM and eventually deploys to act just like other smart contracts we have seen on-chain.

BNB Chain Client (based on Geth) Based on Ethereum Yellow Paper, anyone is allowed to construct their Ethereum node with a programming language of their choice, however, the most popular clients so far go to Geth and Parity. The difference is mainly the language, where Geth is written in Golang while Parity is made of Rust. Among these two, Geth is more popular and thus is the client implementation we use here. BNB Chain Client is a BNB Chain client application based on Geth, where both our BNB Chain nodes (Testnet/Mainnet) are running on it. We can also run our own BNB Chain nodes and local development network with the self-installed BNB Chain clients of our choice.

BNB Studio has integrated all essential development tools including Truffle, Solc, and BNB Chain Client.

Creating Smart Contract Project

BNB Studio integrates a few smart contract templates. You may create your first smart contract project with a corresponding template and start building your smart contract instantly. Built-in templates include:

  • Coin: A basic token-based smart contract
  • Open Zeppelin: A smart contract offers ERC-20, and ETC-721(NFT) tokens, based on Open Zeppelin.
  • MetaCoin: A MetaCoin template based on Truffle.

Contract Deployment and Interaction

BNB Studio offers a one-click automated process to

  1. Contract Deployment
  2. Contract Interaction

Click to view corresponding tutorials on our Github.

Developing a complete dApp

The smart contract we just written is a service running on Binance Smart Chain, it defines a series of on-chain transactions serving the purpose we have set in development. It functions as the backend service in the traditional software practice, so in order to take off the burden of programming, we also need to develop a frontend application to serve as the user interface to the smart contract so that the combination makes a simple, but complete blockchain application, also known as decentralized application or dApp.

A successful dApp project requires all of the following steps:

  • Integrate front-end SDK: A Ethereum-supported SDK like web3.js or ethers.js
  • Configure SDK with BNB Chain RPC interface: Documentation can be found at BNB Chain -RPC
  • Integrate Browser Plugin SDK: such as MetaMask or Binance Chain Wallet
  • Optional Integrate BNB Chain Scan APIs to allow inquiry on-chain data that are not supported by RPC interface (i.e. transaction history, token information)

Here’s a complete BNB Chain dApp Example for your reference.

In this example:

  • Application auto-detect Browser Plugin Wallet, including MetaMask or BNB Chain Wallet;
  • This dApp auto-detects the current network (BNB Chain Testnet/Mainnet);
  • If all tests are passed, A pop-up window will show up to request authorization for access;
  • This dApp offers a transfer button. Input required information and press Execute button, dApp will invoke pop-up windows through the browser plugin where users can sign the transaction to complete it;
  • This dApp provides methods to interact with contracts.

--

--

No responses yet