Cannot get token-id from minted NFT response

I am minting an NFT (using metadata) through the following function in smart contract:

function mintToken(string memory tokenURI)
    public 
    payable
    returns (uint256)
    {
        _tokenIds.increment();
        uint256 newItemId=_tokenIds.current();
        _mint(msg.sender,newItemId);
        _setTokenURI(newItemId,tokenURI);
        return newItemId;
    }

In app side I am using moralis execute function i.e.

const options = {
        chain: 'rinkeby',
        contractAddress: 'deployed contract',
        functionName: 'mintToken',
        abi: this.contractABI,
        params: {
          tokenURI: this.metadata_URL,
        },
      };
      let NFT_smart = await Moralis.executeFunction(options);
      console.log('this is the minted nft');
      console.log(NFT_smart);

But the response of the minted NFT doesn’t contain the token id of the NFT that is minted, and I need that id to perform various functions in the application after it is bein minted such as transfer the NFT.
How can I get the token Id from the minted NFT? Its a high priority task, any help would be appreciated. Thank you
This is the attached output

you should see the logs/events too on a successful mint in the results of that transaction
maybe you have to wait until the transaction is minted on chain, I don’t know the exact syntax now

@cryptokid this is all the logs or event I get with this response that I have posted, however when I open my opensea account the minted NFT is present there with a token Id. I need your assistance

I think that you have to get another response, that one seems to be only for sending the transaction, not for waiting the transaction to be mined on chain.

Try to search for similar forum posts.

Bro, all I want is to get the token Id from the minted item response. Is there any function to get the token id from a specific hash?
@cryptokid

What do you mean with a specific hash?

Like the hash that is returned in the output in the above picture?
Something like when I get the response I call some moralis function to get the token id of the minted NFT through the hash I get in the response? @cryptokid

As cryptokid said, you can get the transaction info after it has been confirmed on-chain and then look in the logs/topics to see if you can get the tokenId:

let NFT_smart = await Moralis.executeFunction(options);
console.log('this is the minted nft');
console.log(NFT_smart);

const tx = await NFT_smart.wait();
console.log("tx", tx);

If you want to look up a specific hash, you can use getTransaction and do the same thing by looking at the logs.

2 Likes

@alex @cryptokid I have solved this by some alteration in the smart contract and then running the function using this:
let NFT_smart = await Moralis.executeFunction(options);
Thanks for your help