In this article you will learn how you can withdraw your funds by direct interaction with the MasterChef contract. This is an essential step you should be prepared for before you enter a farm, as you will not have much time when you will need it.
Step 1: Know the MasterChef address #
In order to use the emergencyWithdraw function you need to know the address of the Masterchef contract and your pool number. If you don’t know your pool ID please read this article and if you don’t know the MasterChef address yet, you can have a look here: How to find MasterChef contract
Step 2a: Use Our Brand New Emergency Withdraw Tool #
As an alternative, we have a brand new tool available for you to use that will automate the rest of this process. Please check it out here:
Step 2b: Navigate to the contract #
It’s always good to learn how to do it the old fashioned way, so here’s the rest of the tutorial:
We’ll use this MasterChef contract as an example.
Navigate to the contract via Polygonscan—a blockchain explorer– then double check the contract address and select the “Write Contract” button in the “Contract” tab.
Step 3: Connect your Wallet to the explorer #
Click on the “Connect to Web3” Link..
..and choose your Wallet.
If you have multiple addresses in your MetaMask wallet choose the right one and click on “Next” in the MetaMask window.
Then connect your wallet by clicking “Connect”.
Maybe you have to refresh the page and click again on the “Connect to Web3” in order to get receive the connected status.
Now you are connected with the MasterChef and you can call the emergencyWithdraw function.
Step 4: Call the emergencyWithdraw function #
Within the “Write Contract” section you’ll find a section called “emergencyWithdraw”.
Enter the pool ID (PID) of the pool you want to remove your funds from and click on “Write”. If you don’t know your pool ID please read this article. Remember to note down the pool ID in case of emergencies, as you will not have much time when you really need the emergencyWithdraw function.
Sign the transaction and you should get a confirmation that the emergency withdraw transaction was successful. If you were fast enough and the developer of the farm has not added some hard rug code in the emergency withdraw function you should now have your funds back in your wallet.
Now you know how to use the emergency withdrawal function by directly interacting with the contract. Being prepared for urgent cases is essential in order to be able to recover your funds, e.g. when the website is not accessible anymore.
If you want to find out how the emergencyWithdraw works for BSC you can read this article.