当我从其他合约调用 ERC20 合约中的传输函数时出错,但是,可以使用 mint/burn

Error when I call transfer function in ERC20 contract from other contract, But, can use mint/burn

我写了 2 份合同

when call "marketBuy" function it can transfer NFT to buyer and can call burn from ERC20 contract. But when I change "burn" function to "transfer / transferFrom" then appear error like this

transact to NFT2.marketBuy pending ... transact to NFT2.marketBuy errored: VM error: revert.

revert The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information.

这是代码

    ...

    function marketBuy(uint _tokenId) public returns (bool) {
        address _buyer = msg.sender;
        uint _price = marketItem[_tokenId].price;

        IERC20(ERC20Token).approve(marketItem[_tokenId].seller, _price);
        IERC20(ERC20Token).transferFrom(_buyer, marketItem[_tokenId].seller, _price);
        transferFrom(marketItem[_tokenId].seller, _buyer, _tokenId);
        
        marketItem[_tokenId].seller = _buyer;
        marketItem[_tokenId].isSold = true;

        return true;
    }
    
    ....

我不知道怎么解决。

对于这一行

IERC20(ERC20Token).approve(marketItem[_tokenId].seller, _price);

来电者是合约本身,不是买方。

所以买家需要在ERC-20合约上手动调用transfer函数