I am developing a smart contract which requires users to upload a specific information about their NFTs. I somehow need to verify whether they are the actual owner of that NFT before uploading information about it. Can you advice me how to do that? I saw that I can use APIs of Opensea, Alchemy, etc. But I was wondering is it possible to do it directly inside my smart contract?

I need something like this:

function approve(uint memory _id, address memory _contractAddress) external {
 address owner = return Owner(_id, _contractAddress);
 require (msg.sender = owner, "not the same owner");

A function which takes the NFT contract address and NFT id and returns the owner address. Then I need to compare whether the owner address is equal to the msg.sender. If they are equal then the user who is calling that function is the owner the the queried NFT.

Is that possible at all or I have to use some API?

Similar functionality I have seen in the Metamask wallet where when importing NFTs we need to provide the contract address and token ID and also in lazy.com NFT tracker website.

1 Answer 1


You can use the ownerOf method of the ERC721 token contract. It takes the NFT id as a parameter and returns the address of the owner 🤙

  • Yes sure, but I also need to specify the contract address somewhere. Because I want to check whether the user is an owner of a specific NFT token id from a specific collection. For example you are an owner of 10NFTs from 10 different collections, how can I check and verify that? If I take ownerOf, I can use it only form my own collection, but what about collections developed by other people?
    – Dakata
    Commented Jul 5, 2022 at 8:22
  • So is the user providing the NFT contract address? If so, you can define an interface with just the ownerOf method, initialize it with the NFT contract address and call the method. If you need to actually find out all the NFT addresses yourself, your best choice is to use one of those APIs
    – Antonio U
    Commented Jul 5, 2022 at 9:01
  • No the user will provide manually the smart contract address of the NFT collection and the ID of the token which needs to be verified. But my question is that possible at all using solidity only or I need to use some third party APIs
    – Dakata
    Commented Jul 5, 2022 at 12:13
  • In that case, you can do t with just solidity. Define an interface and initialize it with the contract address that you receive from the user. Then call the ownerOf method to check if the owner matches with the msg.sender. That should work 😉 You can find more info about interfaces here
    – Antonio U
    Commented Jul 7, 2022 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.