How getApproved return correct address to correct marketplace?? #1530
-
I've a question regarding this code. IERC721 nft = IERC721(nftAddress);
if (nft.getApproved(tokenId) != address(this)) {
revert NftMarketplace__NotApprovedForMarketplace();
}
Now if a user approve it's NFT for multiple marketplaces and put for sale on all of them,... How will NFT return approved address to correct marketplace??? Will it check to see if caller contract is in a map (or some other data structure), if it's there, it return |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hii, |
Beta Was this translation helpful? Give feedback.
Hii,
_tokenApprovals
is mapping used to track approvals for a particular tokenID
and its1-1
it means that at particular instance of time there can be only one approved address(Marketplace)....So if you first approveA
and then approveB
the address of marketplcaeB
will override the_tokenApprovals
mapping for thattokenId
...And when you callgetApproved(tokenId)
function it returns this_tokenApprovals[tokenId]
in our case it will return address ofB
You can take a look at this function implementd here : https://github.com/OpenZeppelin/openzeppelin-contracts/blob/ec825d8999538f110e572605dc56ef7bf44cc574/contracts/token/ERC721/ERC721.sol#L127