0

I'm working on remix and I'm connected to the BSC Testnet.

I am trying to make a transaction of ERC20 tokens in an ERC721 contract by calling the ERC20 contract. However when I try to make the transaction, I get :

"Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? Internal JSON-RPC error. { "code": -32000, "message": "gas required exceeds allowance (30000000) or always failing transaction" }".

I tried to approve the transaction through the ERC721 contract and it worked...

contract RF20 is Context, IERC20 {
    
    //...
    
    function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(_msgSender(), recipient, amount);
        return true;
    }
    
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        _approve(_msgSender(), spender, amount);
        return true;
    }

    
    //...
}


contract RF721 is ERC721{
    
    //...
    
    //I first set the address of ERC20 deployed contract to "connect" to it.
    address addressRF20;
    function setAdressRF20(address _addressRF20) external {
        addressRF20 = _addressRF20;
    }
    
    //This function works.
    function approver() public {
        RF20 contr = RF20(addressRF20);
        contr.approve(0x88849EBf42C66B86cCA7397f0E52824E6e96839a, 50);
    }
    
    //This function does not work.
    function send() public {
        RF20 token = RF20(addressRF20);
        token.transfer(0x88849EBf42C66B86cCA7397f0E52824E6e96839a, 50);
    }
    
    //...
}

Thanks for helping me !

1
  • Usually that error message indicates the transaction's gas (30M) is higher than the block gas limit (13M). – Ismael Mar 8 at 3:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.