2

Everything works for tokens with Token Program (TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA).

import * as solWeb3 from '@solana/web3.js';
import { Metaplex } from '@metaplex-foundation/js';

const connection = new solWeb3.Connection(solWeb3.clusterApiUrl('mainnet-beta'));
const metaplex = Metaplex.make(connection);

const mint = new solWeb3.PublicKey('6Jrb7B3qk1mKo8hNgZYs4HDKCuzJXtPn2gV4nQz6KkCh');
const metadata = await metaplex.nfts().findByMint({ mintAddress: mint });

But with Token 2022 Program (TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb) I get error:

AccountNotFoundError: The account of type [Metadata] was not found at the provided address [8zYwrayHFXcTrVYn1R6LW1vS8Q83u9L7RQt5MsTY6gHb]

I'm tried use Umi follow the advice from this thread: How to get metaplex token metadata for SPL Token 2022?

 import { createUmi } from '@metaplex-foundation/umi-bundle-defaults';
 import { publicKey } from '@metaplex-foundation/umi';

 const umi = createUmi('https://api.mainnet-beta.solana.com');
 umi.programs.bind('splToken', 'splToken2022');

 const asset = await fetchDigitalAsset(umi, publicKey('6Jrb7B3qk1mKo8hNgZYs4HDKCuzJXtPn2gV4nQz6KkCh'));

But got same error

1 Answer 1

3

I've used the getTokenMetadata method from the @solana/spl-token package to get this info.

// Retrieve and log the metadata state
const metadata = await getTokenMetadata(
  connection, // Connection instance
  mint, // PubKey of the Mint Account
  'confirmed', // Commitment, can use undefined to use default
  TOKEN_2022_PROGRAM_ID,
)

Edit

In your case, as per your comment, you can't find it for 6Jrb7B3qk1mKo8hNgZYs4HDKCuzJXtPn2gV4nQz6KkCh on Mainnet.

The snippet below uses the getMint and getExtensionTypes methods from @solana/spl-token to fetch the mint and display all the extension types it has enabled:

const conn = new Connection(clusterApiUrl('mainnet-beta'))
const mint = await getMint(
  conn,
  new PublicKey('6Jrb7B3qk1mKo8hNgZYs4HDKCuzJXtPn2gV4nQz6KkCh'),
  'confirmed',
  TOKEN_2022_PROGRAM_ID,
)

const types = getExtensionTypes(mint.tlvData)
console.log(`Extension Types`, types.map((t) => ExtensionType[t]))

When running the above, it returns an empty array which indicates you didn't enable the metadata pointer extension.

My suggestion is to try minting a new token using this tutorial and make sure it works as expected.

Also, it's recommended to test these things on devnet before creating them on mainnet.

4
  • I tried this method. It returns null package: "@solana/spl-token": "^0.3.11" const connection = new solWeb3.Connection(solWeb3.clusterApiUrl('mainnet-beta')); const mint = new solWeb3.PublicKey('6Jrb7B3qk1mKo8hNgZYs4HDKCuzJXtPn2gV4nQz6KkCh'); const metadata = await getTokenMetadata(connection, mint)
    – bossikkk
    Commented Feb 8 at 14:02
  • It looks like the token did not get initialized properly, it's missing the MetadataPointer extension. Just updated my answer with some code that checks this.
    – beeman
    Commented Feb 8 at 17:05
  • If I can't get the metadata on mainnet how then does solscan.io display the metadata correctly? solscan.io/token/… And did it in 2 ways: using metaplex and from URI (bafkreihbhscshxohriccvbrb2ozcyiagayoy35k7m3ai2a75xuzwew4eee.ipf…) Maybe there is a way to get URI and retrieve metadata through a request?
    – bossikkk
    Commented Feb 14 at 11:49
  • @bossikkk I'm not suggesting this is not possible on mainnet, but it looks like you didn't properly initialize your token, it doesn't have a metadata extension. I suggest you start experimenting (on devnet) with how this works, using my code to figure out if you created it with the right extensions. Once that's good, you can mint it on mainnet.
    – beeman
    Commented Feb 14 at 15:35

Your Answer

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

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