1

I am trying to implement a function, onERC721Received, using Vyper v0.3.3, that is called when an NFT is transferred to the contract using safeTransferFrom. According to the this ERC721 token standard, safeTransferFrom expects the return value to be of type bytes4, but in Vyper 0.3.3 I cannot compile the following code:

@external
def onERC721Received(_operator: address,_from: address,_tokenId: uint256,_data: Bytes[1024]) -> bytes4:
    return method_id("onERC721Received(address,address,uint256,bytes)", output_type=bytes4)

It produces the following error message:

vyper.exceptions.ArgumentException: output_type must be bytes[4] or bytes32

So when I change bytes4 to Bytes[4], as in the code below, the code compiles, but when I try to call safeTransferFrom to transfer an NFT to the contract, the transaction reverts.

@external
def onERC721Received(_operator: address,_from: address,_tokenId: uint256,_data: Bytes[1024]) -> Bytes[4]:
    return method_id("onERC721Received(address,address,uint256,bytes)", output_type=Bytes[4])

How can I implement onERC721Received correctly so that it returns the correct value to safeTransferFrom on the ERC721 token standard cited above?

1

0

Your Answer

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