9

In ERC721 and ERC1155, safeTransferFrom has bytes data parameter.

function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) public;

how do I send data (is it in hex format?) and what does it do?

1 Answer 1

6

Considering you are interfacing with an existing contract (i.e. calling it).

You can send any data you want, such as a string converted to bytes. Here is just one example I have lying around on how to wrangle strings and bytes https://github.com/su-squares/ethereum-contract/blob/master/contracts/SuNFT.sol#L221-L239

The reason why you would do this is application-specific. In other words, only send data if the specific ERC-721 contract you are sending to tells you to, and follow any prescriptions they give you. The myriad ways that applications could describe how you would use these bytes could not be predicted in 2018 (when ERC-721 finalized) and no value existed in cataloging and standardizing these use cases ahead of time.

2
  • Thanks for your answer, but when looking at the openzeppelin's solution , data param is passed to the onERC721Received which does nothing essentially. All the values passed to that function technically do nothing but it only gets the function signature. Am I understanding this correctly?
    – bbusdriver
    Jul 22, 2019 at 16:42
  • 1
    That is correct. OpenZeppelin and 0xcert maintain reference implementations. That means they should have the minimal acceptable feature set. The minimal acceptable feature for onERC721Received is to do nothing and this is how they have implemented it. Jul 23, 2019 at 14:57

Your Answer

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

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