alchemy-sdk-js icon indicating copy to clipboard operation
alchemy-sdk-js copied to clipboard

getNftsForOwner discrepencies between docs, actual results, and typings

Open TheDutchCoder opened this issue 2 years ago • 0 comments

[REQUIRED] Environment

  • Browser version: N/A (Node)
  • Alchemy SDK version: 2.2.3

[REQUIRED] Describe the problem

The docs for getNft (renamed getNftsForOwner) show that, when metadata is enabled, the response should contain an object with keys ownedNfts (this is correct), which is an array of objects with properties like metadata and media.

When running the examples in the docs this is indeed the result that is returned.

However, when running the sdk (2.2.3), the returned result has the following format:

{
      contract: [Object],
      tokenId: '9089',
      tokenType: 'ERC721',
      title: '',
      description: '',
      timeLastUpdated: '2022-11-22T18:34:44.342Z',
      metadataError: 'Malformed token uri, do not retry',
      rawMetadata: [Object],
      tokenUri: [Object],
      media: [],
      spamInfo: undefined,
      balance: 1
},

As you can see, there's no metadata key at all. However there is an undocumented rawMetadata key. This property contains { metadata: [], attributes: [] }, which is incorrect, because there's no metadata property in the typings for rawMetadata:

export interface NftMetadata extends Record<string, any> {
    /** Name of the NFT asset. */
    name?: string;
    /** A human-readable description of the NFT asset. */
    description?: string;
    /** URL to the NFT asset image. */
    image?: string;
    /**
     * The image URL that appears along the top of the NFT asset page. This tends
     * to be the highest resolution image.
     */
    external_url?: string;
    /** Background color of the NFT item. Usually defined as a 6 character hex string. */
    background_color?: string;
    /** The traits, attributes, and characteristics for the NFT asset. */
    attributes?: Array<Record<string, any>>;
}

Long story short: none of these 3 things actually line up properly which makes using the API incredibly difficult.

How to reproduce:

Implement the alchemy-sdk in a Node environment, and do a query on Goerli for an owner. The response is not the same as described in the docs and it certainly isn't the same as the result in the docs tool .

Relevant code or sample repro:

https://stackblitz.com/edit/github-1wqbue-s658mx?file=example.js

Just run npm run example and you'll see my test wallet being used to retrieve a bunch of NFT's (most are "empty"). As you can see, none of them return metadata, all of them return the undocumented rawMetadata, some of them return populated media (this seems to be the most "reliable" property to check.

TheDutchCoder avatar Nov 22 '22 21:11 TheDutchCoder