English 中文(简体)
ERC20 津贴不足
原标题:Once again, ERC20 Insufficient Allowance

I know this question has been asked too frequently. I apologise, but I did not understand much of the answers. I ve been trying to create a Staking Contract but this error has stumped me. This is not the stake function code itself, just the transferring part. This is the code:

   function stake(uint256 _amount) public {
        stakingToken.transferFrom(msg.sender, address(this), _amount);
        stakingToken.approve(msg.sender, _amount);
    }

This is the error:

The transaction has been reverted to the initial state.
Reason provided by the contract: "ERC20: insufficient allowance".
Debug the transaction to get more information.

我先尝试将批准职能放在首位,最后是移交。 Ive利用转账职能进行审判,但都出现了同样的错误。

我也把我的天然气限额提高到12000 000,我也试图增加甲型六氯环己烷,但没有任何工作。

如果问你,我很抱歉,我只想作一个能够解决我问题的翔实答案。

May you reach the stars.

问题回答

问题在于将<条码>核准功能置于<条码><><>:

stakingToken.approve(msg.sender, _amount);

这里的控制流动是为了说明:

     stake()                  approve()
user   -->   staking contract    -->   staking token

从象征性的角度来看,<代码>核准 电话是采集合同,允许用户将taking合同花在上。

But what we wanted is the opposite: the user to allow the staking contract to spend the user s tokens.

<>Solution:为了进行所期望的转让,你必须有两个单独的交易:

  1. The user calls approve directly on the staking token to allow the staking contract to spend the user s tokens.
     approve()
user    -->   staking token
  1. The user calls stake, which transfers the token from the user to the staking contract.
     stake()
user   -->   staking contract




相关问题
Using cURL to download large XML files

I m working with PHP and need to parse a number of fairly large XML files (50-75MB uncompressed). The issue, however, is that these XML files are stored remotely and will need to be downloaded before ...

iphone/mac - how to send video file with a socket?

My program (iphone app) consists of 2 parts - A server socket (sits on port 3490) running on a different thread, and a client to test the server. The server has a video file, and I want to send it to ...

P2P File Transfer c#

Hey, basically I want to send files to my friends through a program, I have been looking on google but I can t seem to find anything. I have found this but it is for C++ and i m looking for C# Any ...

Use PHP to sync large amounts of text

I have several laptops in the field that need to daily get information from our server. Each laptop has a server2go installation (basically Apache, PHP, MySQL running as an executable) that launches ...

热门标签