pistomat / nft-check

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use case 2: Check whether the sender holds an NFT

We check that a sender of a message (msg.sender) is an owner of a specific NFT.

Smart contract logic

  • 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

Implementation

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();

Install

npm install

Run tests

npm run build npm run test

About


Languages

Language:TypeScript 99.0%Language:Solidity 1.0%