How to Emergency Withdraw from the Binance Smart Chain

chuddle
5 min readApr 11, 2021

When the UI is down on a Yield Farm, either because of a technical issue or a deliberate rugpull, you can still withdraw your funds by interacting directly with the Masterchef contract on bscscan.com. I was once (very nervously) able to recover my funds from a rugpulled farm by using this technique. Also, it might be a good idea to practice this a couple of times since you might find yourself a bit nervous when attempting to rescue your crypto. Please keep in mind that this will not work if the liquidity has already been drained from the pool and it will not work for ROI farm contracts. (ROI farms are modern-day pyramid schemes with catchy names disguised as “investments”.)

  1. For this tutorial, I made a small deposit of 0.01 WBNB on the very reputable cheesecakeswap.com.
The stake

2. After making the deposit, go to bscscan.com and search for your wallet address. Your address page will contain every transaction that you have made with that particular wallet. In this case, the URL is https://bscscan.com/address/0x820458CB83fAf6433337F4b972E6191500853AfA

3. Next, scroll down to Transactions and click the record that corresponds to the transaction where you staked your funds, in this case WBNB. This will take you to the Transaction Details page. https://bscscan.com/tx/0x8738a8afb8a4b7f07fdc53cb12ac9589acc28f5c0fd4bf3b22ff0a2ec35f5544

The staking transaction

4. The first thing to note on the Transaction Details page is the “Interacted With (To)”. This is the Masterchef Contract where you will be making your Emergency Withdrawal. You will return to this later.

The MasterChef contract

5. At this point, we want to get the PID for the WBNB liquidity pool. Click the “Click to see More” link at the bottom of the page and scroll down to “Input Data”.

6. Now this is where you might see differences depending on the Masterchef. Sometimes, you may see a “Decode Input Data” button. In this case, all you need to do is click that button and you will see the PID for the transaction.

Notice the Decode Input Data button. Click it!
And there is your PID!

7. On the Cheescakeswap page, the number is already visible at the end of the first line. In this case the number is “8”.

Get ready to be confused because that line with the “8” is actually in hexadecimal format!

8. But wait! That line is actually in hexadecimal format and the value will need to be converted to decimal to get the correct PID. We got lucky with 8 because 1–9 in hex is the same as 1–9 in decimal. It’s after 9 where things get wonky. For example, 10 decimal equals A in hex and 20 decimal equals 14 in hex. Crazy, right? So for anything over 9, you will need to work out the decimal value for yourself using a “Decimal to Hexadecimal converter” which you can find here: Decimal to Hexadecimal Converter (rapidtables.com). Remember the “c” from #6? Plug that hex value into the converter and you’ll get a decimal12. In other words, you’re doing the work of the “Decode Input Data” button yourself.

9. Once you have your PID in hand, proceed to the Masterchef contract by clicking the link in the “Interacted With” section of the Transaction Details. This will take you to the contract page.

The Contract page

10. Next, scroll down to the Transactions section and click the “Contract” tab.

11. At this point, you’ll need to click the “Connect to Web3” link which will prompt you to connect to your wallet.

You aren’t connected to your wallet!
You are now connected to your wallet!

12. Once you’re connected, click “Write Contract” and scroll down to “4. emergencyWithdraw”. Finally, enter your PID (in this case 8) and click the Write button.

You are one click away!

13. And that’s it! Unless the funds were actually drained by a malicious dev, your crypto should now be back in your wallet!

My funds have been moved back to my wallet!

14. If you’ve just been rugged and you have NO IDEA what the MasterChef ID is and don’t have your transaction ID and you think you’re totally screwed, don’t give up! You’ll have to work fast but there’s still hope! There’s a rug-fighting telegram group called the RugSteemer Chat that you can join (https://t.me/rugsteemerchat) and odds are someone there will have the MasterChef ID you need. Once you get that, follow the instructions above but start entering numbers sequentially, starting with 1, into the field described in step #12. Eventually, you’ll hit the PID that corresponds with your pool or pools.

If you have any feedback or questions, I can usually be found in my Lo-Fi Defi Telegram group as chuddle: https://t.me/joinchat/m2ZjBRZFXgcxYjAx

I feel it’s undignified to shill for donations. I wrote this article because I know the pain of getting rugged. But occasionally people insist, so here’s my BSC Address: 0x820458CB83fAf6433337F4b972E6191500853AfA

--

--