-
Notifications
You must be signed in to change notification settings - Fork 11.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should bytes calldata be replaced with bytes memory in IERC721 to prevent compilation errors? #5201
Comments
In conclusion, if you want to pass data as empty object, just cast it into a bytes type : Try doing this, you should not receive any compilation issue. |
Hello @saniksin
When you implement the interface, you are free to change that:
I'm failling to see how the current interface definition is causing any issues. |
@Amxx The issue is whenever you are trying to pass |
It even causes a compilation error with bytes(""). This is a bit confusing. |
Summary
When working with the
safeTransferFrom
function in theIERC721
interface, there are instances where the use ofbytes calldata
leads to compilation errors, especially when trying to pass empty values (e.g.,safeTransferFrom(from, to, tokenId, "")
). In contrast, usingbytes memory
resolves the issue and prevents such errors from occurring.Detailed Description
Currently, the
safeTransferFrom
function inIERC721
defines thedata
parameter asbytes calldata
, which causes issues when trying to pass empty byte arrays or when making certain calls within the implementation. In practice, this often leads to Solidity compilation errors when empty values are used, such as""
, since it can't implicitly convert between string literals andbytes calldata
.Switching the argument type from
calldata
tomemory
in theIERC721
interface and its associated functions resolves the issue without causing any functional or performance drawbacks. Additionally, it aligns with the practical usage patterns seen in many ERC-721 implementations, wherememory
is already frequently used.Question
Is it possible or appropriate to update the
IERC721
interface to usebytes memory
instead ofbytes calldata
for thedata
parameter insafeTransferFrom
?Expected Behavior
IERC721
interface would be updated to usebytes memory
in thesafeTransferFrom
function to prevent compilation errors when passing empty values or making internal calls.Context
This issue primarily affects developers who encounter errors when trying to pass empty byte arrays in contracts implementing the ERC-721 standard. Changing to
bytes memory
resolves these errors and allows for smoother development, especially in cases wheresafeTransferFrom
is called without data.Before and After Example
Before:
After:
The text was updated successfully, but these errors were encountered: