We check that a sender of a message (msg.sender) is an owner of a specific NFT.
- We send NFT smart contract (ERC721) address and NFT ID as parameters to our smart contract method
- We check that the sender of the message (msg.sender) is the owner of the NFT in the provided ERC721 NFT smart contract
Implemented as a modifier onlyOwnerOfNFT
in contract OnlyOwnerOfNFT
contracts/OnlyOwnerOfNFT.sol
It takes an address of ERC721 and token ID as input and checks that the msg.sender is it's owner, reverts otherwise. It is possible to throw a custom error with this code:
if (_nft.ownerOf(_tokenId) != msg.sender) revert CustomError();
npm install
npm run build
npm run test