- 1. Start Tutorial
- 2. BNB React dApp Challenge
- 3. Testing Smart Contracts 💯
-
Write your smart contract, and deploy using Remix IDE
- Save your contract's deployment contract address.
- Same for the ABI code.
-
Create a folder in your workspace directory.
- Run $
npm install create-react-app bnb-react-dapp-tutorial - Run $
npm install --save ethers - Run $
npm start
- Run $
-
Import ethers library into
app.jsat the top of your application's script.
import {ethers} from 'ethers';
-
Import your ABI from Remix into a json file under you
srcdirectory and save -
Import your Contract's ABI into
App.js
import contractABI from './ContractName.json';
- Import the deployed contract's address into
App.js
const contractAddress = '0x....3837837';
- We will use a wallet to connect to the RPC BNB Test Network. Then, we'll create a smart contract and use it to receive a greeting message back to our function. Additionally, we'll add a test case for further confirmation
- Import following code into
App.js
const loadData = async () => {
const provider = new ethers.providers.JsonRpcProvider('https://data-seed-prebsc-1-s1.binance.org:8545');
const contract = new ethers.Contract(contractAddress, contractABI, provider);
const greeting = await contract.hello(); // name of function in solidity contract
alert(greeting);
}
Open Local Host to see the End Result
- You should be able to run the dApp, but you may have already encountered some issues.
- Make sure you have Yarn installed using :
yarn install
- If the ethers library is not working, it's most likely because the version of the ethers library you are attempting to use is out of date, to fix this, try this:
- Run $
yarn remove ethers - Run $
yarn add ethers@5.6.9-- or another version
- Run $
This is a temporary solution to complete the tutorial. However, it's important to note that you can choose different ethers dependencies depending on your specific build. Keep in mind that installing necessary dependencies carries some risks. To determine which version of the ethers library you should install, check the node package manager and yarn.
The objective of this tutorial is to create an application using React or any other framework of your choice using the provided contract ABI and deployed contract addresses.
Your challenge is to design an application that performs the following operations:
- Swap tBNB testnet tokens for WrappedBNB (WBNB).
- Swap BNB for CAKE2 tokens using the PancakeSwap routing contract.
- Enable CAKE2-BUSD token pairing, stake both tokens, and harvest Cake2 token.
- Allow the contract to automatically harvest Cake2 tokens and swap them for tBNB in a unique and interesting way.
- The contract should automatically send tBNB to the BNB CHAIN Charity Wallet.
BNB Charity Wallet Address : 0x8B99F3660622e21f2910ECCA7fBe51d654a1517D
Summary: Staked CAKE2-BUSD tokens will be converted to CAKE2, which will then be swapped for BNB and sent to charity.
Your application should be able to execute all of these tasks smoothly and efficiently.
- Be Sure to Fork 🍴 and leave a Star ⭐
- Create a pull-request & submit your app to show off your hacking skills !
In this tutorial we recommend using pancake purely as an example scenario. You are welcome to use any set of contracts you'd like.
contract : 0xaB1a4d4f1D656d2450692D237fdD6C7f9146e814
contract : 0xFa60D973F7642B748046464e165A65B7323b0DEE
contract : 0x8d008B313C1d6C7fE2982F62d32Da7507cF43551
contract : 0x427bf5b37357632377ecbec9de3626c71a5396c1
- Swap BNB to CAKE2
- Swap Contract: 0x9a489505a00cE272eAa5e07Dba6491314CaE3796
- Wrap BNB to WBNB
- Wrap BNB Contract: 0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd
- Swap WBNB to BUSD
-
'ADD' CAKE2-BUSD with LP Contract (2 tx's) ' Add ' contract : 0x427bf5b37357632377ecbec9de3626c71a5396c1
-
'Stake' CAKE2-BUSD with v3 Router Contract (1 tx) ' Stake ' contract : 0x427bF5b37357632377eCbEC9de3626C71A5396c1
-
Harvest CAKE2 from CAKE2-BUSD stake ^ (1 tx) ' Harvest ' contract : 0x4c650fb471fe4e0f476fd3437c3411b1122c4e3b
-
Swapping CAKE2 to BNB PancakeSwap Contracts + txHash's
-
GOAL : Send BNB Charity Contract Wallet Address Charity Wallet Address : 0x8B99F3660622e21f2910ECCA7fBe51d654a1517D




