1

I am fetching assets stored in my wallet address. I want to seperate the fungible tokens and NFTs , on what basis I can differenciate both of them from data I am fetching from API (opencnft.io) like policy_id or fingerprint or any other factor which differenciates both of them?

3 Answers 3

1

The problem with the given approach of verifying the amount of tokens through the /assets/ endpoint like suggested is that it might guarantee you that it is an NFT currently, but it does not guarantee that it will always be an NFT.

For instance, it might be that the native script "owner" minted only one token currently, but he can still mint however many assets he wants in the future.

In order to actually enforce the policy is locked and guarantee that a specific token is an NFT an always will be, you will need to look at the policy of that script. To do that, block frost offers you the endpoint /script/{hash}/json

For example, in pre-prod, the endpoint https://cardano-preprod.blockfrost.io/api/v0/scripts/ee518da45e3ebe2858669e4eaf7c3c5a7f9be7733e47e0d48c596fd3/json will give you the output

{
    "json": {
        "type": "all",
        "scripts": [
            {
                "type": "sig",
                "keyHash": "87f96fd385bb6911a6f8eb47d97093ce2e3b5db2d884db7b238b0cec"
            },
            {
                "slot": 21561710,
                "type": "before"
            }
        ]
    }
}

Which tell us that this script is governed by two rules. First, it can only be minted by the user with the key 87f96fd385bb6911a6f8eb47d97093ce2e3b5db2d884db7b238b0cec, second that it cannot be minted after the slot 21561710. This second part is what is important for us. NFTs are only guaranteed to be NFTs forever if the this second argument is present and if our current slot is greater than whatever slot is in that script.

6
  • what is the script hash ?
    – Yogesh
    Mar 2 at 5:41
  • @Yogesh it is the minting policy of the token
    – Mateus
    Mar 2 at 8:50
  • How can one retrieve script hash using policy_id or wallet address ?
    – Yogesh
    Mar 2 at 9:37
  • @Yogesh It is the policy ID
    – Mateus
    Mar 2 at 10:07
  • I can't find the API for this to retrieve script hash using policy ID ?
    – Yogesh
    Mar 2 at 12:09
1

The only way to know if a token is an NFT is to check the Minting Policy that was used to create it. There will be the rules used to validate its creation, and you will see if in the rules there are some checks to prevent this Minting Policy to run more than once and to allow only the mint of 1 unit of this token.

There are two kinds of Minting Policies. Old ones with Native Scripts and newer ones with Plutus Scripts.

If they were minted with Native Scripts you need to see in the code some validations like @Mateus explained, with the slot before check:

{
   "slot": 21561710,
   "type": "before"
}

That means that this particular Minting Policy can't run after that slot.

If they were minted with Plutus Scripts you will need to check if the Minting Policy is a parametrized one using an specific UTXO, that the policy is checking that this UTXO is used in the transaction and that the quantity of units of the token minted is 1.

The way to get the code of the Minting Policies is not so clear. With the Currency Symbol of the token you can try to find it in the blockchain. Some times you will find it, most of the times, not.... Some blockchain explorers let developers upload the code of their minting Policies.

Summarizing, there is not a flawless way to probe if a token is a NFT or not. As @Mateus explain also, one token could be a NFT now, but another copy could be done after, and it will not be a NFT anymore. The only way to know that is going to be for ever a NFT is reading the code of the minting policy.

I needed to perform this check in a project I was working for, and I just relay in Blockfrost: https://docs.blockfrost.io/#tag/Cardano-Assets/paths/~1assets~1%7Basset%7D/get

There you can see the "quantity" and the "mint_or_burn_count". Just check if they are both 1. And at least for the moment you are sure that is a NFT.

0

After having a quick look at their API, it looks like it is not possible to find if the token is fungible or not.

You can try to fetch the quantity using the /assets/ Blockfrost's endpoint to see if is just one (NFT) or more (fungible).

Your Answer

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

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