By the end of this lesson, you will be able to:
In this lesson, we provide a detailed demo on how to create, compile and deploy a simple smart contract on the BNB Smart Chain Testnet using the Remix IDE. Remember that, BNB Smart Chain is the component of the BNB Chain ecosystem that is equipped with the smart contract programmability and hence any smart contract or dapps are in essence deployed on the BNB Smart Chain.
Remix IDE is used for the entire journey of smart contract development by users at every knowledge level. It requires no setup, fosters a fast development cycle and has a rich set of plugins with intuitive GUIs. The IDE comes in 2 flavors (web app or desktop app) and as a VSCode extension.
In this lesson, we provide guidelines on how to create, compile, and deploy a simple Hello World smart contract on BSC using the Remix IDE. For this hands-on guide, readers are encourged to perform the specified tasks along for a better understanding.
You must set up all of the following Pre-requisites to be able to deploy your solidity smart contract on BSC:
Remix is an online IDE to develop smart contracts. To be able to use it for writing smart contracts in Solidity programming language, you need to choose Solidity Compiler, make sure to choose the appropriate compiler version. We used 0.8.15
for this tutorial.
HelloWorld.sol
, and paste the contract code given below into it.// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;
contract HelloWorld {
function sayHelloWorld() public pure returns (string memory) {
return "Hello World";
}
}
The first line, pragma solidity ^0.8.15
specifies that the source code is for a Solidity version greater than 0.8.15. Pragmas are common instructions for compilers about how to treat the source code (e.g., pragma once).
A contract in the sense of Solidity is a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereum blockchain. Learn more about the constructor and memory in the docs.
Step1: Click on the button to switch to compile page.
Step2: Select the appropriate compiler version, 0.8.15
in our case.
Step3: Enable "Auto compile" and "Optimization" from Advanced Configurations.
Step4: Select HelloWorld from the contract drop-down menu.
Step5: Click "ABI" to copy the contract ABI and save it.
<img src="https://user-images.githubusercontent.com/93580180/182833004-bd530c91-adb4-4b8c-a87b-70139ef75e35.png" alt="img" style={{zoom:"80%"}}/>
Now, We have to deploy our smart contract on BNB Smart Chain Network. For that, we have to connect to the Web3 world, this can be done by many services like Binance Wallet, MetaMask, Brave, Portis etc. We will be using MetaMask. Please follow this tutorial to setup a Metamask Account for configuring the MetaMask wallet to use with BSC.
Open Metamask and select Custom RPC
from the networks dropdown
Go to setting page
<img src="https://lh5.googleusercontent.com/NqWPIv1MrMJ-W2wDKjxtdxcdFhDwiqhsZ6G6MY6FQnhxPTCCPfPHBJ59vBl1ddxpbfV11ufETWAolV1s9YjCYHPeJCKW1S-sr8gfjcFt3swXM-p3IgafNBqPZ86DvThK-I9gKbrw" alt="img" style={{zoom:"80%"}}/>
<img src="https://lh6.googleusercontent.com/jrq511YshO6rPPx4i-ePRy2gs-66b465c_JFXEW8Cm5CSNTM7CXgCPuFmIh_Im3JlEhxpAqEDDjmUqfskq2m5rG-FKhwZ4_jIenOTdAVs_rMMTjTvZlM6iOpQeivrz_V1liSvuB5" alt="img" style={{zoom:"30%"}}/>
Testnet
Mainnet
Click save to finalize the network setting
Copy the public address of your account from Metamask
Head over to Faucet and request test BNB tokens.
Follow the steps given below to deploy the HelloWorld
smart contract on the BNB Smart Chain Testnet.
<img src="https://user-images.githubusercontent.com/93580180/182833072-ca9cbd50-253e-400b-84c5-720e0ee6bb32.png" alt="img" style={{zoom:"80%"}}/>
<img src="https://user-images.githubusercontent.com/93580180/182833162-4aff06eb-9d20-41c0-a5b6-df996db41a1c.png" alt="img" style={{zoom:"80%"}}/>
<img src="https://user-images.githubusercontent.com/93580180/182833376-8497b8c8-1edf-4f9f-a586-acfbe20ab696.png" alt="img" style={{zoom:"80%"}}/>
Congratulations! You have successfully deployed a simple Smart Contract on the BSC Testnet. Now you can interact with the Smart Contract. Check the deployment status here: https://testnet.bscscan.com/
The first and foremost step is to flatten the solidity contract into a single file to be able to get it verified on BscScan.
npm install truffle-flattener
npx truffle-flattener HelloWorld.sol > FlatHelloWorld.sol
contracts directoryAt this point, you have your flattened and cleaned-up contract ready for the BscScan verification.
This lesson guided you through the basics of creating and deploying a simple smart contract using the Remix IDE and MetaMask Web Wallet. It also provides step-by-step guide on how to verify and publish your deployed smart contract. This tutorial uses testnet, however, the exact same instructions and sequence will work on the mainnet as well.