Get Token Id after minting the NFT immediately from the contract as part of the transaction

Hello everyone, I’m new to flow. I followed the NFT tutorial and successfully minted an NFT. However,
I don’t get the Id of the token minted. I only get the transaction object which contains the transaction Id. I need the Id of the token minted for performing some operations on the metadata. Yes, I’m aware that I can run the getIds() script and get the whole array of the Token Ids stored but in my application continuous minting and depositing of token will take place and I won’t know which token Id belongs to my particular NFT which I just minted. Can you guys help me with this issue?

All I need is the token Id of the NFT Token I just minted in return.

let newNFT ← self.minterRef.mintNFT()

I get a newNFT in the above line which contains the id as well i.e. newNFT.id , but this is inside the transaction’s execute method in the frontend (I’m using FCL). So, this value is not accessible outside.
and I only get transaction id in return. I need newNFT.id to store in my local DB.

I tried one more thing, I immediately called a script to fetch the latest token Ids array, but it return me the old array of Ids on immediate basis as the state of the blockchain get updated after a little time.
When I run the fetch command again, it now returns the latest Ids array.

Please help me out people. I need NFT Id.

Unfortunately, transactions do not have return values, so you can’t return the new ID immediately. You could emit an event with the new ID and check the results for that though! Do you think that would work for you?

Hi,
I have the same problem as Jain, and ok for your response but how can I get the informations on the emit event with fcl please ?
Thanks for your help.

I believe you can add events from your smart contract and then use FCL to catch them like this:

 const response = await fcl.send(
    await sdk.build([sdk.getEvents(eventType, from, toBlock)])
  );

  // Decode server response, so we could get properly formatted values
  const events = await fcl.decode(response);

Thnaks Bruno :ok_hand: