I’m trying to understand how to create a staking token. My purpose is to create a token, in which the user can stake the token and earn interest in the token itself.

We can have two ways to implement this

  1. An ERC20 token with staking functionality, such that the user always interact with this smart contract also for staking
  2. An external contract that has the staking logic

My question is, which approach is the best and when is advised to use the first one rather than the second one and viceversa.

Another question that I have is regarding the following tutorial.

Both the approach implement an ERC20 token with staking capability. What I’m struggling to understand is why, in the stake function, the contract burns the token of the user instead of making a transferFrom of these tokens to the contract itself. If a burn is implemented, then the supply of the token decrease, and I don’t think this is the ideal situation with a staking token. I would rather transfer the amount of token from the user to the contract balance, and then during the unstake I would resend them to the user.

Am I wrong with this thinking and I’m missing something?

First contract stake function:

 function createStake(uint256 _stake)
       _burn(msg.sender, _stake);
       if(stakes[msg.sender] == 0) addStakeholder(msg.sender);
       stakes[msg.sender] = stakes[msg.sender].add(_stake);

Second contract stake function:

* Add functionality like burn to the _stake afunction
function stake(uint256 _amount) public {
  // Make sure staker actually is good for it
  require(_amount < _balances[msg.sender], "DevToken: Cannot stake more than you own");

            // Burn the amount of tokens on the sender
    _burn(msg.sender, _amount);




  • there is no particular reason to do burn or mint except that the staking function is within the token itself. Usually staking is an external contract. And by burning / minting instead of stake / unstake it decreases the total supply, so maybe it is just to make it temporarily deflationary Mar 22 at 20:28


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.