1

I have been trying to get Nft data instead of Metadata from a wallet key. I am using the load function as specified here: https://github.com/metaplex-foundation/js#load

import {Metaplex} from "@metaplex-foundation/js";
const metaplex = new Metaplex(connection);
metaplex.nfts()
        .findAllByOwner({owner: walletKey.publicKey})
        .run()
        .then((nfts) => nfts.forEach(nft => console.log(metaplex.nfts().load(nft))));

However Typescript throws an error: Argument of type 'Metadata' is not assignable to parameter of type 'LoadMetadataInput'. Property 'metadata' is missing in type 'Metadata' but required in type 'LoadMetadataInput'.

Reading the docs show that LoadMetadataInput should take a type of Metadata. What did I do wrong?

@metaplex-foundation/js^0.15.0

1 Answer 1

0

It looks like the shape of input load expects is {metadata: Metadata}. Where you're just passing in Metadata as you said.

Try this:

import {Metaplex} from "@metaplex-foundation/js";
const metaplex = new Metaplex(connection);
metaplex.nfts()
        .findAllByOwner({owner: walletKey.publicKey})
        .run()
        .then((nfts) => nfts.forEach(nft => console.log(metaplex.nfts().load({metadata: nft}))));

Although from that documentation it looks like you might also need to call .run() on the load result. So you might want something more like this (untested):

import {Metaplex} from "@metaplex-foundation/js";

const metaplex = new Metaplex(connection);

const nfts = await metaplex.nfts()
  .findAllByOwner({owner: walletKey.publicKey})
  .run()

nfts.forEach(nft => {
  metaplex.nfts()
    .load({metadata: nft})
    .run()
    .then(loaded => console.log(loaded))
})
1
  • Gee, thanks. I misread the struct as a type declaration. Silly mistake, thanks for pointing it out!
    – Janio
    Commented Aug 31, 2022 at 13:31

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.