· Travis Rodgers · Programming  · 4 min read

How To Use BNB In Remix IDE (instead of ETH)

Not everyone wants to use Ether in their smart contracts, yet the Remix IDE provides this option only. In this post, I'll show you how to actually use BNB instead and how to deploy your contract onto the Binance Smart Chain.

You Can Use BNB Instead Of ETH

I recently created a tutorial where we build out a smart contract for a Bike Rental App.

You can view it here:


And in this smart contract (and application), we are using BNB and deploying it to the Binance Smart Chain.

As you may know, the Remix IDE is set up to use Ether by default.

It can’t be changed. There’s Wei, Gwei, and Ether.

However…it just so happens that ETH and BNB on the Binance Smart Chain both use 18 decimals.

Hmm…

That means we can actually treat ETH as BNB in the Remix IDE!!

So 0.01 ETH, though it is a much different value in USD compared to BNB, can be used in Remix as BNB as well, with no conversions.

If I visit the Ethereum Unit Converter page and convert 0.01 ETH to Wei we get 10000000000000000 Wei.

Well, this 10000000000000000 Wei (or 0.01 ether) is also equal to 0.01 BNB when used on the Binance Smart Chain. Again, not in USD value, but the Binance Smart Chain will rightly interpret the value.

A Practical Example of Depositing BNB From Remix

Let’s test this out.

1. Create a Test Contract

Open Remix IDE, create a new Solidity file, and add the following:

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

contract TestBNB {

    // Deposit to smart contract
    function deposit(address walletAddress) payable public {}

}

2. Deploy the Smart Contract to BSC

Now deploy the contract to the Binance Smart Chain.

To do this:

  1. Add the Binance Smart Chain Testnet (we don’t want to spend real BNB) to your Metamask wallet. Instructions are here.
  2. Send some test BNB to your wallet. This faucet will give you 1 BNB per day. Be sure you are on the BSC Testnet in Metamask before step 3.
  3. In the Remix IDE change your environment to Injected Web3. Now confirm the connection to your Metamask wallet if it is not already connected. You should see your account listed like so, which means you’re connected (Custom (97) network):

Finally, hit the deploy button to deploy your Smart Contract to the Binance Smart Chain Testnet.

3. Make a Deposit to Confirm BNB is Working Correctly

Now, the moment of truth.

Go ahead and deposit 0.005 BNB to the smart contract. Be sure to enter this as Wei which would be 5000000000000000 Wei.

Add this amount into the Value field (be sure Wei is selected), add your wallet address (we are sending from that) to the Deposit field, and choose Deposit.

And when the Metamask transaction confirmation comes up for your to confirm, you’ll see that it has the right amount of BNB set which is 0.005 BNB (plus gas).

There you have it!

Conclusion

So in summary, you don’t actually have to do anything. They both use 18 decimals.

So 0.001 ETH is the same as 0.001 BNB and will be interpreted rightly on their respective chains.

    Share:

    Related Posts

    View All Posts »