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?

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.

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.