1

I'm trying to get my onERC721Received function to revert with a super obvious require statement failure but it seems to go through and transfer the ERC721.

I've tried other things like comparing the operator or from address to msg.sender and trying both != and == just to try to get it to revert and nothing seems to work.

contract Reject is IERC721Receiver { 

    function onERC721Received(address operator, address from, uint256 tokenId, bytes memory) public override returns(bytes4) {
        require(true == false, "true not false, duh");

        return bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"));
    }

}

This function should definitely be able to revert, right?

1
  • I am observing this same behavior
    – dalton_c
    Feb 27, 2022 at 22:58

1 Answer 1

0

I tried to reproduce the error with the following code in remix.

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";

contract Reject is IERC721Receiver { 

    function onERC721Received(address operator, address from, uint256 tokenId, bytes memory) public override returns(bytes4) {
        require(true == false, "true not false, duh");

        return bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"));
    }

}

However, it was not possible. The transaction is reverted with the following reason: "true not false, duh". For me the code works as expected...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.