1

Some functions from ERC-721 interface contain payable modifiers.

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

I was wondering why it is payable and found from EIP-721 that explains why.

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.

Does this mean that when a function in the interface includes payable and when it is implemented, it can be changed to anything? such as public, view, pure? or did it mean that it can only be changed to nonpayable which is nothing? I don't get why it is not

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

in the first place. Also the definition Mutability guarantees is hard to understand. Can someone explain this in a simpler way please?

1

Does this mean that when a function in the interface includes payable and when it is implemented, it can be changed to anything?

Yes, payable is the least-strict form of mutability, so your implementation of the function can use a stricter mutability if you want it to.

Also the definition Mutability guarantees is hard to understand. Can someone explain this in a simpler way please?

Basically, any function that is payable, can implicitly anything that a non-payable function can do.

Any non-payable function can implicitly do anything that a view function can do.

And any view function can implicitly do anything that a pure function can do.

But the same is not true in the opposite direction.

So if a function in the interface is view, its a guarantee that your function can read data if you want it to, but not write data or accept msg.value.

  • Great answer. For reference, just wanted to point out the first bullet point in ERC-721's caveats section. Changes were made to Solidity as part of passing ERC-721 and this note provides additional context and answers to "OMG why does transfer cost money!!LL??". – William Entriken Jul 21 at 23:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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