6

I was researching the ERC721 standard on Openzeppelin and I have noticed that there is not public or external "transfer" function.

I see internal "_transfer" function, that is called by "_safeTransfer" (which has internal visibility too) and transferFrom (public function).

I want to make sure that the only way to transfer an ERC721 token (NFT) is using the "transferFrom" function. Is there any other way to let users transfer their NFTs directly from their wallets, without requiring to indicate their address in "transferFrom" function?

In ERC20 standard the "transfer" function gets the owner using msg.sender property. Why ERC721 does not implement the same mechanism?

1 Answer 1

6

We did not include a transfer function because it may be ambiguous whether you mean to transfer something that you are the owner of versus something you are authorized to get.

The current owner must always be specified, because of security reasons (specifically, front-running). This is why transferFrom is the closest to the wire you can get.

3
  • 1
    Thanks too much for the explanation, makes totally sense! Apr 22, 2022 at 22:03
  • 1
    @william-entriken, could you give an example of a front-run attack that could be performed if a transfer function would have been included in ERC-721, as well? I can't imagine one...
    – Iaroslav
    Apr 7 at 20:57
  • 1
    A marketplace is transferring an NFT from Bob to Mary (among many other "legs" of a transaction). However, immediately before this leg, Bob sells that asset to Steve. Result: Bob is paid for sale to Steve and sale to Mary, but only Mary gets the asset. Apr 8 at 16:31

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.