Sitemap

Lab 9: Hello World Contract on Binance Smart Chain (BSC) with Remix IDE

6 min readMar 5, 2023

--

This blog post is a lab manual for the Web3LabsForAll project. Web3LabsForAll is an open-source project to help new students or professionals start their web3 journey by providing no-setup, hands-on experience. Join the Beta on Discord (https://bit.ly/sign-up-beta-discord) or fill out this form (https://bit.ly/sign-up-beta-form).

The lab 8 manual can be accessed here:

What is Binance Smart Chain?

Binance Smart Chain (BSC) is a blockchain developed by the cryptocurrency exchange Binance. It was created to offer a high-performance blockchain that enables developers to build decentralized applications (dApps) and programmable smart contracts.

BSC operates as a parallel chain to Binance Chain, but with some additional features and capabilities, including the ability to execute smart contracts using the Ethereum Virtual Machine (EVM) and support for the BEP-20 token standard.

BSC also offers faster transaction speeds and lower fees compared to the Ethereum network, making it an attractive alternative for developers looking to build dApps and other blockchain-based solutions.

The Binance Smart Chain network uses a Proof-of-Stake (PoS) consensus mechanism, where validators stake BNB (Binance’s native token) to secure the network and earn rewards. Validators are responsible for verifying transactions and adding new blocks to the blockchain.

Official Website: https://www.bnbchain.org

Activity 1: Deploying a Smart contract

We will use Remix IDE with Metamask to deploy the smart contract on the BSC blockchain.

Step 1: Open Remix online IDE in the browser provided with the lab.

Press enter or click to view image in full size

Step 2: Click on the “Contracts” section to view the sample contracts provided by the Remix IDE. You can select any contract from the available ones. We are selecting the “1_Storage.sol” contract written in Solidity language.

Press enter or click to view image in full size

The program has following two functions:

  • store(uint256 num): Set the passed value in the number variable.
  • retrieve(): Reads and returns the stored value of the number variable.

As this is our Hello world program, we are not going to make any modifications to it.

Step 3: Click the “Compile” button to compile the code and to make sure there are no issues/errors.

Press enter or click to view image in full size

Once the code is compiled, you will be able to see the build directory with compiled smart contracts.

Activity 2: Configuring Metamask with BSC Test Network

Step 4: Click on the “Deploy” button to access the deployment section.

If we check the Metamask plugin, we can observe that it is currently using the “Ethereum Mainnet” network.

Note: Password for lab Metamask is “password”.

In order to use this to deploy Smart Contract on the BSC test network, we need to add the network. Click on the “Add network” button.

Press enter or click to view image in full size

On the next step, the BSC mainnet is in the list but the BSC test network is not present. So, it has to be added manually.

Click on the “Add a network manually” option.

Press enter or click to view image in full size

Step 5: Take the network details from an article provided on the Binance Academy.

URL: https://academy.binance.com/en/articles/connecting-metamask-to-binance-smart-chain

Press enter or click to view image in full size

Fill the details in the “Add a network manually” form and click “Save”.

Press enter or click to view image in full size

The network will be added. However, we will need to get BNB tokens from the faucet. Copy the “Account 1” address.

Press enter or click to view image in full size

Step 6: Open Binance testnet Faucet portal.

URL: https://testnet.binance.org/faucet-smart

Get web3author’s stories in your inbox

Join Medium for free to get updates from this writer.

Paste the account address in the text field and select 0.5 BNB from “Give me BNB” drop down list.

Press enter or click to view image in full size

The next step will show a confirmation message.

It takes a few minutes for the faucet to send BNB.

Press enter or click to view image in full size

Once the BNBs are sent, they will reflect in the wallet.

Step 7: Select “Injected Provider — MetaMask” from the ENVIRONMENT drop-down list.

Select “Account 1” and click “Next” on the wallet popup.

Metamask will show you the permissions that are required by Remix IDE and once you agree to those, the “Account 1” will be connected to the IDE.

Note: If you have already allowed “Account 1” access to Metamask. You won’t see any messages and it will directly work.

In our example, we had allowed “Account 1” while deploying on the Polygon Mumbai network in Lab 8. Hence, we didn’t get any message asking for permissions.

Press enter or click to view image in full size

Step 8: The setup is ready. Click the “Deploy” button to deploy the contract.

Deploying a smart contract is done by making a transaction on the blockchain. Metamask will be invoked to make the transaction. Check “Gas Fee” and click the “Confirm” button.

Press enter or click to view image in full size

Step 9: Once the transaction confirmation on Metamask, the contract will be deployed.

You will also see a message confirming the deployment in Remix IDE and will be able to access the deployed contract in the “Deployed Contracts” section.

Press enter or click to view image in full size

Step 10: On clicking Metamask confirmation message, one can view the transaction details on BSC blockchain explorer.

Press enter or click to view image in full size

We can now interact with the smart contract.

Activity 3: Interacting with the Smart contract

Step 1: Store a value say 15 to the smart contract by entering “15” in the textbox and press the “store” button.

This is a write operation, so Metamask will be invoked to make a transaction. Again click “Confirm”.

Press enter or click to view image in full size

The value of the variable will be updated to 15.

Again, on successful execution of a transaction, Metamask will show a transaction confirmation popup.

Press enter or click to view image in full size

And, clicking Metamask confirmation message will show the transaction details on BSC blockchain explorer.

Press enter or click to view image in full size
Press enter or click to view image in full size

The transaction details clearly show that store() method was called.

Step 2: The value stored in Step 1 can be verified by clicking the “retrieve” button.

Press enter or click to view image in full size

The output shows that 15 is stored in the variable.

It is important to note that the read operation doesn’t require a transaction so Metamask won’t be invoked and no Gas fee will be spent.

Video on Youtube

If you liked the blog, please spread the word by sharing it or giving claps to this blog so that it can reach more people.

For more information on Web3, follow us on:

Instagram: https://www.instagram.com/web3verseacademy/

Twitter: https://twitter.com/Web3verseAcad

LinkedIn: https://www.linkedin.com/company/web3verse-academy/

--

--

web3author
web3author

Making Web3 easy, one step at a time.