0

Reference : https://eips.ethereum.org/EIPS/eip-721

I was going through the official documentation from eips.ethereum.org for ERC721. I have some doubts from the interface of ERC721 :

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;

function approve(address _approved, uint256 _tokenId) external payable;

function setApprovalForAll(address _operator, bool _approved) external;

As you can see , all 4 of the above functions are setter functions ( they set values in Blockchain's state ) .

My first question is why are these functions made payable ? As far as I know , when a function is made payable , it ( and the contract that it belongs to ) is able to receive ether . If our only goal is to receive ether , then we can also do that by making only one function payable . Why are 3 functions made payable ?

Second question is why setApprovalForAll is non-payable ?

1 Answer 1

0

If a function is payable, it means you can send ether when calling it. This means the function will still execute, no matter if the sender sent some eth or not. Therefore any function can be set as payable.

In your case, the functions referenced have a hierarchy described in the Caveats section. If a function is set as non-payable then it can't be implemented as payable.

You do not necessarily have to do it this way. If you take a look at Openzeppelin's ERC721, they do not have payable for any of these functions.

Now when it comes to setApprovalForAll, I would say they did it this way for security reasons. Probably they wanted to have one approval function, which does not accept ETH and one which does, so it covers all the different scenarios of usage.

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.