11

It used to be solana token list but it's deprecated now.

How do you search for metadata using new metaplex API?

Answer:

const mintData = await (
      await metaplex
        .tokens()
        .findMintByAddress(new PublicKey(USDC_TOKEN_ADDRESS))
    ).run();

    const mintData = await (
      await metaplex
        .nfts()
        .findMintWithMetadataByAddress(new PublicKey(USDC_TOKEN_ADDRESS))
    ).run();

Although for now I find metadata from solscan more useful.

4
  • 2
    as posed, this question is subjective and will elicit opinionated response. consider rewording it objectively
    – trent.sol
    Jul 12, 2022 at 21:39
  • 1
    You should probably include which data specifically you'd be looking for. You can get token info directly from a node, but the question is will that be sufficient for the use case you're building? Jul 12, 2022 at 21:43
  • What data do you need? The answer will be different for different types of data. Like if you just need a logo and the price and the name - CoinGecko API is probably best.
    – 22289d
    Jul 13, 2022 at 1:40
  • There is actually an official alternative described in the README of deprecated token-list. It is now using Metaplex's metadata standard to store additional info like image, url, etc: readme
    – rxdx
    Jul 13, 2022 at 11:08

3 Answers 3

1

This shows how to get the metadata, is on the token creator github.

const getMetadata = useCallback(
async (form) => {
  const tokenMint = form.tokenAddress; // Your token mint address
  const metadataPDA =  await findMetadataPda(new PublicKey(tokenMint)); // You can use findMetadataPda method to get the PDA for token mint where metadata is stored
  console.log(metadataPDA.toBase58());
  const metadataAccount = await connection.getAccountInfo(metadataPDA); // Get the account info from the PDA 
  console.log(metadataAccount);
  const [metadata, _] = await Metadata.deserialize(metadataAccount.data); // Deserialize the metadata from PDA account 
  console.log(metadata); // Here you have the details
  let logoRes = await fetch(metadata.data.uri);
  let logoJson = await logoRes.json();
  let { image } = logoJson;
  setTokenMetadata({ tokenMetadata, ...metadata.data });
  setLogo(image);
  setLoaded(true);
  setTokenAddress('')
},
[tokenAddress]

);

The full source code is here: https://github.com/jacobcreech/Token-Creator/blob/master/src/components/GetMetadata.tsx

1
  • please replace the screenshot with text in a code block. also annotate it to explain how it answers the question. as is, this is effectively a "url-only answer"
    – trent.sol
    Aug 2, 2022 at 6:20
0

Not sure about the "best" API, but documentation on using Solana's official APIs can be found here:

https://docs.solana.com/cluster/rpc-endpoints

Furthermore, there are a few endpoints you can use to get token information in the API specs, listed here:

https://docs.solana.com/developing/clients/jsonrpc-api

Since you mentioned coingecko, they also have an API that lets you query data on any asset they list, using the "API id" listed on any asset's info page on their site:

https://www.coingecko.com/en/api/documentation

2
  • 2
    The answer is not pointing towards relevant information. I updated my original questions to be more specific and answered since I found solution Jul 26, 2022 at 21:44
  • Yeah, I see you completely changed the question since I took the time to answer the prev question, lol.
    – M. K.
    Aug 1, 2022 at 14:23
0

You can check out this tutorial too: Metaplex Solana NFT metadata – How to get NFTs metadata.

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.