Lesson 15: NftMarketplace approve() to access any NFT for listing #2749
-
Hi all, Is it mandatory (in Production) to
code of function listItem (address nftAddress, uint256 tokenId, uint256 price)
external
notListed (nftAddress, tokenId, msg.sender)
isOwnerOrApproved (nftAddress, tokenId, msg.sender)
{
if(price <= 0) {
revert NftMarketplace__PriceMustBeAboveZero();
}
IERC721 nft = IERC721(nftAddress);
if(nft.getApproved(tokenId) != address(this)) {
revert NftMarketplace__NotYetApprovedForMarketplace();
}
s_listings[nftAddress][tokenId] = Listing(price, msg.sender);
emit ItemListed(msg.sender, nftAddress, tokenId, price);
} |
Beta Was this translation helpful? Give feedback.
Answered by
RoboCrypter
Sep 20, 2022
Replies: 1 comment 3 replies
-
@ManuWeb3 : Yes, It is mandatory as well as the good practice! Because you just don't want any contract to have access to your nft, You as a Owner should have to approve that contract first! |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
ManuWeb3
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ManuWeb3 : Yes, It is mandatory as well as the good practice!
Because you just don't want any contract to have access to your nft, You as a Owner should have to approve that contract first!