6

In the ERC-721 spec interface, the functions safeTransferFrom, transferFrom and approve all have the payable modifier. What is the reason for this? As far as I can tell, none of these functions require it, and I'm not sure what I should be doing with the value.

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

function safeTransferFrom(address _from, address _to, uint256 _tokenId) external payable;

function transferFrom(address _from, address _to, uint256 _tokenId) external payable;

1 Answer 1

5

It appears the answer is to do with mutability, from the "Caveats" section of the ERC721 spec,

Solidity issue #3412: The above interfaces include explicit mutability guarantees for each function. Mutability guarantees are, in order weak to strong: payable, implicit nonpayable, view, and pure. Your implementation MUST meet the mutability guarantee in this interface and you MAY meet a stronger guarantee. For example, a payable function in this interface may be implemented as nonpayble (no state mutability specified) in your contract. We expect a later Solidity release will allow your stricter contract to inherit from this interface, but a workaround for version 0.4.20 is that you can edit this interface to add stricter mutability before inheriting from your contract.

So the functions are marked payable as a way of explicitly not requiring that these functions are view or pure.

Here's a link to the discussion of issue #3412, which discusses mutability guarantees.

Your Answer

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

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