Solidity and ERC-721 – What is the Bytes Data Param in safeTransferFrom?

erc-721solidity

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?

Best Answer

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.

Related Topic