2

I trying to get the metadata of a token 2022 using gill but this only return a empty object.

I using this method:

import {fetchMetadata} from 'gill/programs' const { data: dataA } = await fetchMetadata(client.rpc,tokenMintA) 

But this always return this object dont mind what address I send:

{ "key": 1, "updateAuthority": "1112ypLNWEBMaTDBbckFKKA7CdLNRXjyyjoeEKrj9Rq", "mint": "JBxB5pbbddafuMjSoCm4WsehW6F1X68eAJgFShoUgvaB", "data": { "name": "", "symbol": "", "uri": "", "sellerFeeBasisPoints": 0, "creators": { "__option": "None" } }, "primarySaleHappened": false, "isMutable": false, "editionNonce": { "__option": "None" }, "tokenStandard": { "__option": "None" }, "collection": { "__option": "None" }, "uses": { "__option": "None" }, "collectionDetails": { "__option": "None" }, "programmableConfig": { "__option": "None" } } 

Is there a param I missing in the fetchMetadata method?

or we have other way to get this metadata using gill?

Thanks in advance for the help💯

2 Answers 2

3

You are on the right track with this!

Here is a clean solution that uses the correct functions from the kit and also adds support for when the metadata is stored on a different mint. you might want to support other metadata programs (like metaplex) as well (depending on you usecase)

const mintAccount = await fetchMint(rpc, mint); const maybeTokenExtensions = mintAccount.data.extensions; if (isSome(maybeTokenExtensions)){ const tokenExtensions = maybeTokenExtensions.value; const metadataPointer = tokenExtensions.find(extension => isExtension("MetadataPointer", extension)) if(!metadataPointer){ console.log("Error: this token doesn't have a metadata pointer"); return; } const maybePointerAddress = metadataPointer.metadataAddress; if (isNone(maybePointerAddress)) { console.log("Error: the metadata pointer doens't point anywhere"); return; } const pointerAddress = maybePointerAddress.value; const metadataAccountInfo = (await rpc.getAccountInfo(pointerAddress, {encoding: "base64"}).send()).value; if (!metadataAccountInfo) { console.log("Error: could not get account info for metadata account"); return; } let programHandlingMetadata = metadataAccountInfo.owner; console.log("The metadata is handeled by "+programHandlingMetadata); if (programHandlingMetadata === TOKEN_2022_PROGRAM_ADDRESS) { console.log("metadata handled by Token22"); let extenstionsContainingMetadata = tokenExtensions; if (pointerAddress===mint){ console.log("metadata is in token mint"); } else { console.log("metadata is in a different token mint! because that is totally possible!"); const mintWithMetadata = await fetchMint(rpc, pointerAddress); const extensions = mintWithMetadata.data.extensions; if (extensions && isSome(extensions)){ extenstionsContainingMetadata = extensions.value; } else { console.log("Error: could not get mint account containing metadata"); return; } } const metadata = extenstionsContainingMetadata.find(extension => isExtension("TokenMetadata", extension)) if(!metadata){ console.log("Error: this token doesn't have a metadata extnsion"); return; } console.log(metadata.name); } else { console.log(programHandlingMetadata+ " program not supported."); // TODO add metadata support for other programs } } 

Thanks for inspiring me with this question! I'll have a video on this topic coming out out soon ;)

2
  • thanks for your response, I gonna improve my implementation with the code you share. I will stay tuned to your YouTube channel to learn more about solana💯 Commented Sep 12 at 19:03
  • video is out now ;) youtu.be/YInBj_5cQ5E Commented Oct 22 at 13:39
2

I find the answer, since the token extension add the metadata in the same address now you can get the metadata getting the mint of the token.

import {fetchMint} from 'gill/programs' const { data: tokenAInfo } = await fetchMint(client.rpc, pool.tokenMintA) if (tokenAInfo.extensions.__option === 'Some') { const tokenMetadata = tokenAInfo.extensions.value.find((ext) => ext.__kind === 'TokenMetadata') } 
2
  • 2
    While it's great you found a fix; I think it's worth clarifying that the metadata isn't necessarily stored in the Mint; That's why the Metadata Pointer Extension is used in conjuction with the Metadata Extension; So my point is it can point to another Account that isn't necessarily the Mint Commented Sep 12 at 7:07
  • @AsaboroDaniel yhea, thanks for clarifying. Commented Sep 12 at 18:56

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.