Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

281
Visualizações
Error when I call transfer function in ERC20 contract from other contract, But, can use mint/burn

I write 2 contracts

  • ERC20
  • ERC721 with additional function for buy it.

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.

This is the code

    ...

    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;
    }
    
    ....

I don't know how to solve this.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

For this line

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

the caller is the contract itself, it isn't the buyer.

So the buyer needs to call the transfer function manually on the ERC-20 contract

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda