openzeppelin-contracts
openzeppelin-contracts copied to clipboard
Support for Custom Errors in ERC721 and 1155 onReceived hooks try catch
🧐 Motivation
Right now ERC1155 and 721 checks on safeTransfers do a try {} catch {} with only a catch on string and then a global catch that returns the default ERCXXXX: transfer to non-ERCXXXXReceiver implementer
This leads to always getting the default revert string when reverting in an onERCXXXReceived hook with a Custom Error, which does not allow the caller to get accurate revert reasons.
It would be very nice for testing purpose and also to show the right reason of reverts on the front-end, to bubble the revert code when it's a custom error
📝 Details
It is possible to easily bubble revert codes using this simple code before or after the catch on string:
} catch (bytes memory reason) {
assembly {
revert(add(32, reason), mload(reason))
}
}
That is indeed a very good point.
I hoped solidy would support that without assemble :/
Can you make a PR ?
Sure, I will work on this during the week and make one.
I added check that confirm that ERC721 already support Custom error emitted by receive hook.
I submitted a PR that aligns ERC1155's implementation with ERC721's
hey i am new to open source can you please suggest me, how to contribute