A NFT Token transfer is successful when,
msg.senderis the owner of contract
msg.senderis approved for all for the owner
msg.senderis approved for that token by the owner
Scenario 1: If Token is minted on the NFT Marketplace itself
This means that the owners of NFT Marketplace contract and NFT Token contract are the same.
- This means that the NFT Token Contract should have given NFT Marketplace Contract approvals to transfer/manage all the tokens minted in NFT Token Contract. This permission has to be given when NFT Token contract is deployed in blockchain, which also mean, you need to deploy marketplace contract before token contract.
- First step to sell the NFT token is to make sure that the, buyers has sent the required money to the NFT marketplace Contract to make the purchase.
- We can transfer NFT token ownership from NFT Marketplace Contract (as the marketplace has require permissions) using,
IERC721(nft_token_contract_address).safeTransferFrom(current_owner_address, new_owner_address, tokenId)
- This is like a final action from a blockchain perspective, that does change on actual blockchain and tokens.
- But we also parallely keep record of all tokens and ownerships in marketplace of its users. Hence we may need to update our backend database records reflecting this transaction.
Scenario 2: If Token was already minted and now it is listed on the NFT Marketplace
- In this case, the marketplace will not have permissions to purchase/sale the NFT Token.
- The owner of the NFT Token has to give approval to the NFT Marketplace Contract to sell/purchases the NFT Token. The 3rd point .
- We need to first call the NFT Token Contract (from frontend libraries such like ether.js) and fetch the permissions for the NFT Marketplace Contract.