2

Using web.js, I am trying to transfer erc721 tokens across different addresses. In case of cryptokitties, I can do the transfer using transfer function only while in case of cryptoheroes, I can use the same contract but do the transfer only using transferFrom.

What exactly is the difference between the two? How can I write a generic code which will work when I want to transfer the tokens for all ERC721 contract? Or do I need to have the contract ABI for each contract?

2 Answers 2

3

The function transferFrom in token contracts refers to the transfer of tokens that you do not own, but rather have been approved to spend. It is used together with the approve function, when an address establishes a certain allowance of tokens for another address to spend for them. Hence, when using transferFrom you establish what address the tokens that you are spending are coming from, whereas transfer is just for your own tokens.

And regarding interaction between contracts, you could implement a function to allow transfers of tokens from other contracts directly in your smart contract. However, web3.js is not going to help you achieve that if the function is not present in the smart contract itself. For that, you'd have to specify the contract addresses and ABIs to interact with separately.

2

There is no transfer in ERC-721. Source:

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

transferFrom is superior because you may have authority from multiple people to send any given NFT. That means a transfer is ambiguous whether it is coming from yourself or from someone else that authorized you to send it.

But I know I’m sending it from myself because I’m the one who currently owns it

Not really. “Currently” is a funny concept on the blockchain. So you cannot be sure of the exact state of the system when you make a transaction. This is why transferFrom is designed to atomically check for you.

—-

So why does CryptoKitties have bare transfer? Because CK was deployed before the final EIP was standardized.

4
  • "There is no transfer" -> this is false if I look in the link or I haven't understand what you mean.
    – David
    Nov 14, 2021 at 20:12
  • @David Perhaps you are seeing event Transfer(...), that is an event, not a function. Or are you seeing something else? Nov 15, 2021 at 0:40
  • function transferFrom(address _from, address _to, uint256 _tokenId) external payable;
    – David
    Nov 15, 2021 at 0:43
  • Got it. The OP differentiated a transfer(...) and transferFrom(...) function. You found the transferFrom and there is no transfer (in the standard). Nov 15, 2021 at 0:58

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.