If you are looking for a smart contract that can be executed on the BNB Chain (aka Binance Smart Chain) successfully using the two most liquid traded exchanges (Pancakeswap V3 and Pancakeswap V2), then this will be the perfect code package for you.
This is not for newbies to programming or solidity. Developing smart contracts can feel highly challenging, particularly for folk new to the blockchain ecosystem so some experience is advised.
Download package
Add environment variables
Change directory into your project folder and add a .env file:
cd myproject
touch .env
Add the below to your .env file, remember to replace the private key with your own, prefixed with “0x”:
MAINNET_PROVIDER_URL=https://bsc-dataseed.binance.org
TESTNET_PROVIDER_URL=https://data-seed-prebsc-1-s1.binance.org:8545
PRIVATE_KEY=ENTER_YOUR_PRIVATE_KEY_PREFIXED_WITH_0x
Install Packages
Within the myproject (or whatever you have named your project folder) install the EXACT packages as shown:
~/myproject
yarn --exact
npx hardhat compile
Test flashloan smart contract
Due to the configurations in the hardhat.config.ts file, your test will fork the mainnet and provide a thorough test for a basic swap:
~/myproject
npx hardhat test
Make sure to watch the video above which will talk on this and how the smart contract works in more detail.
Deploy to mainnet
Once you are satisfied with your smart contract and tested any changes you make fully, you can submit this to the blockchain using:
~/myproject
npx hardhat run scripts/deployFlash.ts --network mainnet
It will be important to ensure your private key is valid and in full working order when performing this step.
Your smart contract is complete
Well done! Working with smart contracts and swaps on the BNB chain can be very challenging. You have successfully proven you can now take part in this using Flashloans which is super advanced stuff.
One note of caution: MEV bots look for smart contract transactions which call Flashloans to frontrun them. If you have not seen the code package on submarine sends, it is recommended to do so for your awareness.