2

So, let's say I have a mint address, take USDC's mint address as an example: EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v

How can I now get the logo for that token with just the mint address?

=> I'm looking to do this on the FE

2 Answers 2

3

There's an old registry that is deprecated (but some tokens have not upgraded), so best idea is to check it:

import { TokenListProvider } from "solana-token-list";
  //...
  const tokenListProvider = new TokenListProvider().resolve();
  const tokenList = (await tokenListProvider).filterByClusterSlug('mainnet-beta').getList();
  let result = tokenList.find(token=>token.address===mint.toString());

Then check the metaplex metadata:

import { Metaplex } from "@metaplex-foundation/js";
//...
  const sft = await METAPLEX.nfts().findByMint({ mintAddress });

https://github.com/amilz/burnspl/blob/cb78135ae4baeec598eb8cc367d4a646970f7276/app/utils/metaplex.ts#L6

3

To preface this answer, I am currently employed by Helius.

Another way to accomplish this is to use the Token Metadata endpoint from Helius, here.

This will allow you to pass in 100 mint accounts at once.

Here is an example I put together:

const url = "https://api.helius.xyz/v0/token-metadata?api-key=<api-key>"

const nftAddresses = [
  "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
]; // USDC

const getMetadata = async () => {
  const response = await fetch(url, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      mintAccounts: nftAddresses,
      includeOffChain: true,
      disableCache: false,
    }),
  });

  const data = await response.json();
  console.log("metadata: ", data);
};

getMetadata();

Where you get this as a response:

{
    account: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
    onChainAccountInfo: { accountInfo: [Object], error: '' },
    onChainMetadata: { metadata: [Object], error: '' },
    offChainMetadata: { metadata: null, uri: '', error: 'OFFCHAIN_URI_EMPTY' },
    legacyMetadata: {
      chainId: 101,
      address: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
      symbol: 'USDC',
      name: 'USD Coin',
      decimals: 6,
      logoURI: 'https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v/logo.png',
      tags: [Array],
      extensions: [Object]
    }
  }
]
2
  • 1
    Hey Hunter, this is a correct answer but as per stackexchange TOS, you have to disclose your affiliation with the Helius labs. I'm sure your intentions are honorable, but lets not make anyone else have any doubts about it! 👏 Commented Jul 29, 2023 at 5:04
  • 1
    Thanks @JosipVolarević, just updated this!
    – hunter
    Commented Jul 31, 2023 at 16:16

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.