[SOLVED] MoralisDataObjectValue and EvmNftContractType missing in. v.2.0.9

After updating to version 2.0.9 I canā€™t find where to import MoralisDataObjectValue and EvmNftContractType from . . .
All documentation seems to refer to old version - Where can I find data for latest?

Iā€™m guessing it was changed to here . . . .

But is there documentation somewhere instead of crawling through the files to find it?

Correct, types are exported from @moralisweb3/common-evm-utils and @moralisweb3/common-core-utils.

We are working on updating the technical docs: https://moralisweb3.github.io/Moralis-JS-SDK This might help you as it has also a search function.

I thought I had fixed the upgrade everywhere but Iā€™m having trouble with the IPFS resolve now on images . . . I couldnā€™t find any docs on how to remedy this error:

The IPFS resolver looks like this:

image

And I changed imports of metadata to new node links . . .

Can you help?

What does the error on image_url and contractType say ?

./src/components/modules/NFTCard/NFTCard.tsx:26:38
Type error: Property ā€˜image_urlā€™ does not exist on type ā€˜MoralisDataObjectValueā€™.
Property ā€˜image_urlā€™ does not exist on type ā€˜MoralisDataObjectValue[]ā€™.

maybe that object doesnā€™t have an image_url?

It worked like that in v.2.1.3 but a lot changed in Node_modules in v.2.0.9 and I canā€™t find the documentation so Iā€™m a bit lost , , ,

I dont know why there was no error in other version, but the metadata which you get from nft endpoint is in the form of json string. So you have to access the image url from parsed json and to fix the typescript error you have to define a type again like below.

interface metadata  {
name: string, 
description: string, 
image: string
}
// access the image url like this
(JSON.parse(metadata as unknown as string) as metadata).image

Not sure I understand . . . I built from the ā€œoldā€ ethereum boilerplate and upgraded to v2.0.9
Iā€™m thus using types like this:

image

image

And trying to use it in the NFT card . . .

Ahh okā€¦It seems like the metadata is already parsed in file pages/balances/nft.tsx and passed as json.

There is no fixed type defined for metadata in sdk as well, So you can also add custom metadata types to fix this error.

Update this type in src/components/templates/balances/NFT/types.ts file

export type TNFTBalance = {
  tokenAddress: string;
  chain: string | number;
  ownerOf: string | undefined;
  blockNumberMinted: string | undefined;
  blockNumber: string | undefined;
  tokenId: string | number;
  contractType: EvmNftContractType;
  tokenUri?: string | undefined;
  tokenHash?: string | undefined;
  metadata: { // you can add more types here, depending on the metadata standard.
    name: string;
    description: string;
    image: string;
  };
  name?: string | undefined;
  symbol?: string | undefined;
  lastMetadataSync?: Date | undefined;
  lastTokenUriSync?: Date | undefined;
  amount?: number | undefined;
};

Thanx a lot that makes sense - But maybe Iā€™m completely daft, but I canā€™t find EvmNftContractType anywhere to import from under @moralisweb3 . . . What am I not getting here?? :stuck_out_tongue:

I did not find it either. Maybe it is renamed or removed, Not sure.

However, you can use also contractType as string since the data in contractType is always either ERC721, ERC1155, or any other NFT standard. That should be ok for satisfying typescript.

contractType: string;

Alright great <3 . . . However I found that you need to set the image like this for it to work:

image

Thanx for the help - Catch you on the next one :slight_smile:

1 Like