I am building a staking contract that accepts an ERC20 token set by the owner.

contract ECommerce {
    IERC20 token;
token = IERC20(**"I insert the token address here"**);

Here are some important functions:

Stake token

     function stake(uint256 _tokenamount) public returns(bool) {
           require(_tokenamount <= GetAllowance(msg.sender), "Please approve tokens before transferring");
           token.transferFrom(msg.sender, address(this), _tokenamount);
           return true;

Allowance checker

 function GetAllowance(address _tokenOwnerAdd) public view returns(uint256){
       return token.allowance(_tokenOwnerAdd, address(this));

I get the error with the unstake function:

unStake token

     function unstake(uint256 _tokenamount) public returns(bool) {
           require(_tokenamount <= UserTokenBalance[msg.sender], "You cannot unstake more than you staked");
           token.transferFrom(address(this), msg.sender, _tokenamount);
           return true;

The unstake function just says: "Error will be thrown in contract execution"

Yes, the contract does have gas. And The user does have enough balance.

Any help would be appreciated - thank you!

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.