How to get to know that for which NFT the transaction has taken place?

I have uploaded the image and got IPFS link, I minted this IPFS link using solidity and my transaction was also successful but how I can know that transaction has took place for that image only.
Any idea about it.

You can create a view function to check which data is stored on the blockchain.

can you please give me code for it.

// SPDX-License-Identifier: Unlicense

pragma solidity ^0.8.4;

import “@openzeppelin/[email protected]/token/ERC721/extensions/ERC721Enumerable.sol”;

import “@openzeppelin/[email protected]/token/ERC721/extensions/ERC721URIStorage.sol”;

import “@openzeppelin/[email protected]/token/ERC721/ERC721.sol”;

import “@openzeppelin/[email protected]/utils/math/SafeMath.sol”;

contract MyToken is ERC721, ERC721Enumerable, ERC721URIStorage {

using SafeMath for uint256;

uint public constant mintPrice=0;

function _beforeTokenTransfer(address from, address to, uint256 tokenId)


    override(ERC721, ERC721Enumerable)


    super._beforeTokenTransfer(from, to, tokenId);


function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage){



function tokenURI(uint256 tokenId)



    override(ERC721, ERC721URIStorage)

    returns (string memory)


    return super.tokenURI(tokenId);


function supportsInterface(bytes4 interfaceId)



    override(ERC721, ERC721Enumerable)

    returns (bool)


    return super.supportsInterface(interfaceId);


constructor() ERC721("YTMinter", "YTM")  {}

function mint(string memory _uri) public payable{

    uint256 mintIndex = totalSupply();

    _safeMint(msg.sender, mintIndex);

    _setTokenURI(mintIndex, _uri);



This is my code, and want to add view function in this,

You already have that function in you code.

When you call the tokenURI(tokenId) function it returns the URI of the token id which is stored in the smart contract.

You can call this function after a successful mint transaction to check if the the correct URI is stored.

1 Like

can you please tell what code should be added and after which line. It will be helpfull.

This is that function. It is already in your code.
No need to add anything extra.

so should i write it after mint function ?

Not required. Your solidity code should work fine.

it is working fine, but how will I will get to know transaction is for same NFT

Call the tokenURI from your app with token id in the input parameter. It will return you the token URI.

Here is an example:

// ABI of my tokenURI function
abi = 		{
		"inputs": [
				"internalType": "uint256",
				"name": "tokenId",
				"type": "uint256"
		"name": "tokenURI",
		"outputs": [
				"internalType": "string",
				"name": "",
				"type": "string"
		"stateMutability": "view",
		"type": "function"

const options = {
  contractAddress: "0x20D8af71c9D55788A770367FE9Ca668B6a1776E8",
  functionName: "tokenURI",
  abi: [abi],
  params: {
      tokenId: "0", // this will be token id for which you want to check the tokenURI
const transaction = await Moralis.executeFunction(options);

You can try this with your contract address, ABI and tokenID to check if it is returning the correct uri.