2

I'm trying to recover the metadatas of various tokens in solana. I'm using the web3.js library and the multiplex library.

To do this, I'm already trying to retrieve the metadatas in multiplex. If they don't exist, I'm trying to retrieve the embedded metadatas (the metadata extension).

here is a pseudo code:

import { TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID, getMint, getTokenMetadata } from '@solana/spl-token'
import { fetchDigitalAsset, mplTokenMetadata } from '@metaplex-foundation/mpl-token-metadata'
[.....]



const getMetadata(): .... {
    const metadata = await this.tryFetchMetaplexMetadata(mint)
    if (metadata) {
         return metadata
    }

    const mintInfo = await getMint(connection, new PublicKey(mint), undefined, tokenProgramID)
    const splMetadata = await getTokenMetadata(connection, new PublicKey(mint), undefined, tokenProgramID)

    return splMetadata
}

private async tryFetchMetaplexMetadata(mint: string): xxxx {
    try {
      const umi = createUmi(url)
      umi.use(mplTokenMetadata())
      const metaplexMeta = await fetchDigitalAsset(umi, publicKey(mint))
      return metaplexMeta
    } catch (error) {
      if (!(error instanceof AccountNotFoundError)) {
        throw error
      }

      return undefined
    }
}

I am curently testing it in devnet it does work well when metadata are in multiplex (like So11111111111111111111111111111111111111112) or if the token has the metadata extension (like 6ENgWfakvxVDU8E73oX9V1yf4bGbfagxN5WqpVx1BKQ)

However, I found a token (gV82zaLUfThSmTzdzjjLzfxxW94rcFDB6MYMMvee3g1) that doesn't have multiplex and has a metadata pointer extension (but no metadata extension).

I am not really sure how to retrieve metadata for this token. I tried to use the metadata account (pointed by the metadata pointer) and try to interact with the Assigned program ID but I don't really know how to do

Any help is welcomed!

1 Answer 1

2

To make your work easier, make the fetches using the DAS API and an RPC provider that supports it like Helius.

Codewise, this would take the form.

import {
    keypairIdentity,
    publicKey,
} from "@metaplex-foundation/umi";
import { dasApi } from "@metaplex-foundation/digital-asset-standard-api";
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";

const umi = createUmi(
    `https://devnet.helius-rpc.com/?api-key=${process.env.HELIUS_API_KEY}`
);

umi.use(keypairIdentity(keypair)).use(dasApi());

const fetchUsingDAS = async () => {
    const collectible = await umi.rpc.getAsset(
        publicKey("6ENgWfakvxVDU8E73oX9V1yf4bGbfagxN5WqpVx1BKQ")
    );
    console.log("\n", collectible);
};

fetchUsingDAS()
    .then(() => console.log("success: "))
    .catch((error) => console.error(error));

The code above makes use of UMI and the DAS plugin

2
  • Thanks a lot for your answer! Wasn't aware of DAS Api, it's nice indeed! For my problematic example (aka gV82zaLUfThSmTzdzjjLzfxxW94rcFDB6MYMMvee3g1) DAS Api doesn't return symbol nor name. Is it a problem during the creation of the Token2022?
    – Pedro
    Commented May 24 at 7:26
  • using solana FM I can't find metadata also - solana.fm/address/…. Is it set up when minting?
    – Jimii
    Commented May 24 at 7:59

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.