'Do I need to use approve method in ERC721?
I am practicing the smart contract and NFT looks interested to me.
ERC721 written in Vyper
What is the mechanic of approve in it?
What is isApprovedForAll
does?
IMO. I don't need to use approve method. I just use transferFrom()
is enough.
Correct me if I am wrong
Solution 1:[1]
The approval mechanism is described in more depth in the ERC-721 standard.
What is the mechanic of approve in it?
A token owner can approve another address (an operator) to spend a specific token using the approve()
function, as well as all of the owner's tokens using setApprovalForAll()
.
What is
isApprovedForAll
does?
It's a getter function returning bool
value whether an operator address can spend all of the owner tokens (i.e. they have been approved using the setApprovalForAll()
function) - or not.
I don't need to use approve method. I just use transferFrom() is enough.
Correct if you're only spending your own tokens.
If you want another address to spend your tokens, or if you want to spend tokens belonging to another owner (possibly one of your other addresses), you'll need to use the approval mechanism.
Solution 2:[2]
Remember, with ***approve()***
the transfer happens in 2 steps:
You, the owner, call approve and give it the _approved
address of the new owner, and the _tokenId
you want them to take.
The new owner calls transferFrom
with the _tokenId
. Next, the contract checks to make sure the new owner has been already approved, and then transfers them the token.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Petr Hejda |
Solution 2 | Jeremy Caney |