📜Staking Contracts

Staking platforms on DeFi are made possible through the use of so called ‘’Smart Contracts.’’ A smart contract is basically an agreement between two people in the form of computer code. They run on the blockchain, so they are stored on a public database and cannot be changed. Once a smart contract is written and deployed by the creator, its functions cannot be changed anymore.

The transactions that happen in a smart contract are processed by the blockchain, which means they can be sent automatically without a third party.

For this tutorial we will go through the life cycle of a staking contract from deployment to end date. We will also explain some of the most important functions that can be used.

🔸Getting started🔸

You can go directly to our staking platform by clicking on this link.

🔸Finding the staking contract🔸

Many staking platforms don’t offer users a direct possibility to view the staking contract. To find the staking contract when it’s not linked on the staking platform you will need to use bscscan.com and manually find the staking contract.

For the sake of user friendliness, Yummy added all the staking contracts links directly on the platform. To view the contract simply open the pool you want to explore. For this Tutorial we will take an inactive YD-YUMMY staking contract.

After you expand the pool you will see a direct link to the staking contract.

Note: if a platform doesn’t provide a direct link to the staking contract go to bscscan.com and find a TX where an interaction was made with the contract. Such as a ‘’Deposit’’ TX.

The contract that was interacted with is the staking contract.

🔸Checking deployment🔸

By clicking on ‘’View contract’’ it directly takes you to the bscscan.com page for the contract.

From this page you can basically use most functions in the contract. To see when or by who a staking contract was created, go to the ‘’Internal Txns’’ tab.

For this example the YD-YUMMY contract was created 29 days ago. To see the details of this contract’s deployment click on the ‘’Parent Txn Hash.’’

As you can see above the contract was created by ‘’Yummy Crypto: Deployer.’’

🔸Checking ownership🔸

After deployment the ownership of the contract must the transferred. This can be seen in the ‘’Logs.’’ But it can also be seen on the staking contracts ‘’Transactions.’’

From here go to the very last page of the transactions. The very first transaction is the ‘’Transfer Ownership’’ TX.

🔸Checking rewards distribution🔸

To see the TX where the owner sets the rewards per block, search in the ‘’Transactions’’ tab for a TX that says ‘’Set Rewards Per Block.’’

After opening the TX details, click on the ‘’Logs’’ tab.

Here you can find the rewards per block. As seen in this example it was set to 5208333333333. Yummy has 9 decimals in it’s coding, making the actual number of rewards 5208.333333333 YUMMY/Block.

🔸Reading contract information🔸

You can use bscscan.com to directly interact with the smart contract and use it’s functions. To look into the contract go to the ‘’Contract’’ tab.

On this page you can view the full code, read contract, and write contract functions.

We won’t go in depth of the coding in this tutorial, but let’s take a look at some contract information. Click on the ‘’Read Contract’’ button to proceed.

Here you can see the ‘’REWARD_TOKEN,’’ in this case Yummy. The ‘’STAKE_TOKEN’’ which is YUSD. The ‘’bonusEndBlock’’ which will show you the ending block of the contract. To see when this is, simply copy it and paste it in the search bar in bscscan.com.

You can also see the contract owner, which in this case is the same owner of the Yummy V2 contract and all other staking contracts. The key to this wallet is been kept by Yummy’s CEO.

Also the rewards can be seen again here. They will get updated if the ‘’Set Rewards Per Block’’ function is used by the owner.

Keep in mind the value is including the 9 decimals again, so in this case 5208.333333333 YUMMY/Block.

The start block can also be found here, again simply copy it and paste it in bscscan.com search bar to receive the exact time.

🔸Using contract functions🔸

As mentioned before you are able to directly interact with the smart contract through bscscan.com. To use the contract’s functions go to the ‘’Write Contract’’ tab. Click on ‘’Connect to Web3'’ to connect your DeFi wallet to bscscan.com.

When you click the ‘’Connect to Web3,'’ you will need to approve the action within your DeFi wallet.

When successfully connected the red dot will turn green. Now you can write smart contract functions.

🔸Emergency withdraw🔸

We will not go through all the function into detail, but let’s take a look at one very important one called ‘’emergencyWithdraw.’’

This function is designed to withdraw the entire staked amount from a staking pool, vault or farm. In a case of hack, exploit, or simply a scam attempt from a dev, the user can use this function to withdraw his principal even if the staking site is offline. Connect the DeFi wallet like previously explained and simply click on ‘’Write’’ in this function. An approval in the DeFi wallet will be needed but if successful the entire staked amount will be withdrawn back into the users wallet.

We at Yummy always recommend to test out the emergency withdraw whenever you start using a staking contract. This method can be used on practically all platforms.

Keep in mind not every staking contract has this function. A staking contract without an emergency withdraw is widely considered unsafe to use and should be avoided.

🔸Exipration date reached🔸

When a staking platform reaches it’s end block it stops rewarding tokens. On most platforms the pool moves to an ‘’inactive/completed/ended’’ tab. At this point the only thing a user can do is withdraw his principal amount and (auto)harvest the rewards.

This concludes the staking contracts tutorial. All methods described work on basically all staking contracts. We advice every user of staking platforms to do his/her own research and look into the contracts before making any deposits.

Our staking contracts are very closely based on ApeSwap’s contracts. ApeSwap is known for having one of the safest staking platforms in BSC.

If you experience any issues using our staking platform, feel free to reach out to us in the official Telegram chat. We at Yummy are all about education and safety. If you have issues with other contracts not related to Yummy you can also reach out to us and we will gladly assist in any way possible 👍

Last updated