为什么在合约中转erc20token会一直失败?

// SPDX-License-Identifier: MIT
pragma 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 方法中,使用transfer和transferFrom都会报错. 前面已经进行过approve了, 调用deposit的地址也有代币.

请先 登录 后评论

1 个回答

Tiny熊 - 布道者
  擅长:智能合约,以太坊
请先 登录 后评论
  • 1 关注
  • 0 收藏,2989 浏览
  • ANYFC 提出于 2021-05-11 11:01

相似问题