MEGA-GUIDE: How To Interact Directly With Smart Contracts Like A Chad (Gain An Edge Over All Other Virgin Farmers)

DeFi Chads
8 min readFeb 16, 2021

This is a special BSC Chads guide on how to farm directly through smart contracts on Etherscan or BSCScan, instead of relying on the web UI interfaces.

This gives you an unfair advantage over those who don’t know how to do this. It’s literally like having cheat codes in a video game.

And we’re sharing this because we want to bring true value to our subscribers instead of just another Telegram announcement channel.

Why is interacting directly with smart contract so powerful? Because…

  • Developers always deploy contract first, then integrate UI later. Understanding how to use the contracts directly can give you a big head start and allow you to get into the pools first if the UI isn’t up yet
  • During periods of high traffic, the website may go down and only chads who understand how to interact with smart contracts directly will be able to use everything as normal, while 99% of people will be stuck
  • If a project rugs, they will take down the website but they can never take down the smart contracts. If you know how to unstake/sell/etc through the smart contracts, you may be able to salvage some money

Now, I’m gonna be upfront with you

This stuff can be pretty complex and confusion. Most people won’t take the time to properly learn and understand this stuff. Some will do fine regardless, but most will have fun staying poor.

So I promise you learning this stuff will be worth your time because this knowledge can create fortunes for you when the right opportunity presents it self.

For instance, last month, I was farming some algo-stable coin that just launched. No one could stake in one of the pools because the “UI had a bug” (how many times have we heard this excuse before??)

So I browsed through Etherscan and found the farming contract. I was able to stake my tokens before everyone else. I ended up gaining 65% of the pool share within the first 2 hours. The next day, I was able to completely exit for a 25 ETH profit.

It wasn’t easy, but at least it was honest work 😉

So to make everything as clear as possible, we’ll go through an example using Pancake Swap, since it is one of the most forked farming contracts.

Although every project will have different farming contracts, once you try this a few times, you’ll quickly get the hang of it and will be able to apply these methods to new farms you’ve never seen before.

Ready? LFG.

Example: Farm CAKE Rewards By Staking CAKE-BNB LP on PancakeSwap

So most farming pools will use these 2 contracts:

  1. The stake token contract. This is what you need to stake in order to receive the reward token. Usually some sort of liquidity token. For our example we’ll use the CAKE-BNB CAKE-LP token
  2. The farming/staking contract. This contract manages the staking, unstaking, withdraws, etc. It’s also commonly known as the MasterChef contract

So first, how do you find these contracts? I’m assuming you already have a basic understanding of how to use Etherscan or BSCScan.

If you’re lucky the project will post these addresses transparently.

If that’s not the case, you can do some digging on BSCScan to find them yourself.

  1. The staked token contract is usually some sort of liquidity token (CAKE-LP). You can find it directly on Pancake Swap by searching the pair and going into the “pair info” section at the bottom

2. The farming / staking contract might be a bit harder to find if the project doesn’t post the address.

You can usually go into the reward token (CAKE) contract on BSCScan and look at “top holders”.

Look for the “contract” icon beside the top holders. One of these is usually the farming contract, because the farming contract will hold the majority of the reward tokens.

If you click into the contract itself, you’ll see the name as “MasterChef” or some variation.

First, let’s review the steps to farm using the UI

Now, you’ll probably already know how to farm the normal way. But read through the follow along anyways because it will give you context for everything afterwards.

  1. Add liquidity to create your staked token (ie CAKE-BNB LP)

2. Approve the staked token (CAKE-BNB LP) to be used by the farming contract

In the backend, we are basically give permission for staked tokens (CAKE-BNB CAKE-LP) to be used by the farming contract.

3. Deposit the staked token into the farming contract

Now that the farming contract has permission to spend our staked tokens, we are depositing them into the farming contract.

4. Harvest rewards from the farming contract

Here, we are interacting with the farming contract and claiming our rewards.

5. Unstake your staked token from the farming contract

This is the opposite of step 3. We are withdrawing the staked tokens from the farming contract.

Now, let’s go over how to farm directly in BSCScan

We’re going to be working with 2 contracts here:

  • Staked token contract (CAKE-BNB LP): 0xa527a61703d82139f8a06bc30097cc9caa2df5a6
  • PancakeSwap Farming/Masterchef Contract: 0x73feaa1ee314f8c655e354234017be2193c9e24e

Now, let’s follow the same sequence of steps from above:

  1. Add liquidity to create your staked token (ie CAKE-BNB LP) — we’re going to cover this part in a future article because it’s a bit complex. For now we’re going to assume you have the LP tokens already.
  2. Approve the staked token (CAKE-BNB LP) to be used by the farming contract

Here, we go into the staked token contract and give the farming contract permission to spend a high number of tokens.

So we go to the CAKE-BNB LP contract and click “write contract

Next we connect Metamask or whatever wallet you’re using:

Once connected, find the “approve” function and enter the following:

  • spender: farming contract address (0x73feaa1ee314f8c655e354234017be2193c9e24e)
  • value: amount to approve — put a large number for virtually unlimited (999999999999000000000000000000)

Note: you’ll need to multiply your numbers by 1000000000000000000 (1 with 18 zeros or 1e18) when entering them in. I don’t know why but it’s just how Ethereum/BSC works.

So if I want to give the contract permission to approve 99999999999 tokens, I’ll need to enter 99999999999000000000000000000.

If I want to use 420.69, I’ll need to enter 420690000000000000000.

Next, Write the contract and a Metamask prompt should pop up, and you send the transaction as normal.

3. Deposit the staked token into the farming contract

Now that we approved the farming contract to spend the staked token, we can actually deposit the staked tokens into the farming contract.

To do this, go into the farming contract, click “write” and connect your wallet.

Look for the “deposit” function

You’ll need to enter in the _pid or pool ID, and the amount of staked tokens to deposit.

The _pid can be a bit tricky to find. You’ll have to go into “Read Contract” find “poolinfo” and type in integers starting from 0 until you find the lpToken address of your staked token.

In this case, we are looking for the CAKE-BNB LP token which is 0xa527a61703d82139f8a06bc30097cc9caa2df5a6.

So here, the _pid is 1.

Once we have the pool ID, we decide how many tokens to stake. Again, we just type in the number of LP tokens to stake and add 18 zeros. If we want to stake 2 CAKE-BNB LP tokens, we would enter this:

Click “Write” and send the transaction as normal.

Note: If you get an error in your Metamask like this, it could mean a few things:

  1. You didn’t approve the token properly
  2. Your pid is incorrect
  3. You don’t have enough staked tokens to deposit

Do some debugging to figure figure out what you need to do.

4. Harvest rewards from the farming contract

Now the way the Masterchef contract was written, harvesting or claiming your tokens is done automatically every time you deposit or withdraw tokens.

So there is actually no “claim” function in the contract. When you harvest, you are actually just depositing 0 tokens into the contract.

So to harvest your current rewards, simply deposit 0 tokens:

Note: Some farming/staking contracts will have a “claim” function which you can call to claim your current rewards.

5. Unstake your staked token from the farming contract

Withdrawing your tokens is the opposite of depositing them.

Find the function called “withdraw” and enter your pool id and the amount you want to withdraw.

Pro Tip: Check “Input Data” In Your Transactions

You can always check the Input Data in your transactions in in BSCScan whenever you interact with a smart contract through the UI to see what happened in the backend.

This is a helpful way to learn exactly what actions are doing, so you can become more familiar with how these smart contracts work.

In the transaction details, click to see more, then click “Decode Input Data”

Congrats, now you understand smart contracts better than 95% of degens

This information can be a lot to digest, and I promise you, the more you try this out, the more comfortable you’ll get interacting directly with smart contracts.

You’ll gain a huge competitive edge when it comes to farming and DeFi in general.

Be sure to subscribe to our Telegram announcement channel BSC Chads for more guides, alpha leaks and all things BSC.

Happy farming chads!

Unlisted

--

--