1

Using this code:

import { Connection, PublicKey } from '@solana/web3.js';
// strong text@metaplex-foundation/mpl-token-metadata": "^2.13.0"
import { Metaplex } from '@metaplex-foundation/js';

const RPC_URL:string = "https://broken-summer-shape.solana-mainnet.quiknode.pro/**[YOUR_KEY]**/";
const MINT_ADDR:string = "4sp2EUDrQf46rZun6sYAWzjrXwUpx2T3njuoKmV766RJ"; //HAMI

(async()=>{

    let connection:Connection = new Connection(RPC_URL);
    const metaplex = new Metaplex(connection);

    try{
        const nftMetadata = await metaplex.nfts().findByMint({ mintAddress: new PublicKey(MINT_ADDR) });
        console.log(JSON.stringify(nftMetadata));
    }catch(e){
        console.log((e as Error).message);
    }
})();

I can get metadata (o empty data) for tokens account, for example:

const MINT_ADDR:string = "5DPKMXmf9WK1C6N1MoJLWjYApiP4KR8zNf1oofevGEub"; // SPL TOKEN
const MINT_ADDR:String = "C1w2uRGBAA8FPoovchBVAb1uuVEqs6g77TCHe2bbJG8G"; // Ceramonio

But I can NOT get answer for this token even when it has metadata:

const MINT_ADDR:String = "C1w5UgaszaJxAstFtaPSXej6nwk8EcSQdc5dkxm6ruVr"; // Javia Brown-Turner

Any idea?

2 Answers 2

3

you are using the deprecated API for the Metaplex SDK.

Please switch to UMI and the metadata package

import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
import { fetchDigitalAsset } from '@metaplex-foundation/mpl-token-metadata'
import { dasApi } from "@metaplex-foundation/digital-asset-standard-api";

const umi = createUmi(clusterApiUrl("devnet"));
umi.use(keypairIdentity(keypair)).use(mplTokenMetadata()).use(dasApi());

const MINT_ADDR:String = "C1w2uRGBAA8FPoovchBVAb1uuVEqs6g77TCHe2bbJG8G"; // Ceramonio

const fetchAsset = async () => {
    const asset = await (await fetchDigitalAsset(umi, publicKey(MINT_ADDR)));
    console.log("asset \n", asset);
}

Alternatively, you could use the DAS API to fetch the token details

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

REF -> https://developers.metaplex.com/token-metadata/fetch

2
  • Did you test your code?, I miss publicKey, keypairIdentity, keypair... Commented May 23 at 17:16
  • I post below your code with those problems solved. Thanks a lot. Commented May 23 at 17:34
0

Based on Jimii answer but solving some code problems:

import { createUmi } from "@metaplex-foundation/umi-bundle-defaults"; // ^0.9.1
import { fetchDigitalAsset, mplTokenMetadata } from '@metaplex-foundation/mpl-token-metadata'; // ^3.2.1
import { clusterApiUrl, PublicKey } from '@solana/web3.js'; // ^1.91.7
import { publicKey, PublicKeyInput } from "@metaplex-foundation/umi"; // ^0.9.1

const umi = createUmi(clusterApiUrl('mainnet-beta')).use(mplTokenMetadata());
const MINT_ADDR:PublicKeyInput<string> = "C1w2uRGBAA8FPoovchBVAb1uuVEqs6g77TCHe2bbJG8G"; // Ceramonio

const fetchAsset = async () => {
    const asset = await fetchDigitalAsset(umi, publicKey(MINT_ADDR));
    console.log("asset \n", asset);
}

fetchAsset();

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.