current position:Home>Why does the transfer of erc20token in the contract always fail?

Why does the transfer of erc20token in the contract always fail?

2022-02-04 00:28:47 Q & A of Denglian community

// SPDX-License-Identifier: MITpragma solidity >= 0.8.0;import "@openzeppelin/contracts/token/ERC20/ERC20.sol";import "@openzeppelin/contracts/token/ERC20/IERC20.sol";contract C {    function deposit( uint amount, IERC20 _token)        public    {        _token.transferFrom(msg.sender,address(this), amount);        _token.transfer(address(this), amount);    }}

deposit In the method , Use transfer and transferFrom All will report wrong. . It has been done before approve 了 , call deposit Your address also has tokens .






Other answers 1:

copyright notice
author[Q & A of Denglian community],Please bring the original link to reprint, thank you.
https://en.netfreeman.com/2022/02/202202040028450807.html

Random recommended