Skip to content

Commit

Permalink
chore(tezos): nft metadata fetching fix
Browse files Browse the repository at this point in the history
  • Loading branch information
D4mph1r committed Sep 10, 2024
1 parent 850bbb8 commit 71f18ca
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/contractsTypes/tezos/NFT.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ export type Storage = {
}
>
};
token_metadata: BigMap<
nat,
{
token_id: nat;
token_info: MMap<string, bytes>;
}
>;
metadata: BigMap<string, bytes>;
admin: address;
};
Expand Down
25 changes: 21 additions & 4 deletions src/handler/tezos/utils/nftData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import type { TezosToolkit } from "@taquito/taquito";
import { Tzip16Module, bytesToString, tzip16 } from "@taquito/tzip16";

import type { NFTContractType } from "../../../contractsTypes/tezos/NFT.types";
import { tas } from "../../../contractsTypes/tezos/type-aliases";
import {
type MMap,
type bytes,
type nat,
tas,
} from "../../../contractsTypes/tezos/type-aliases";
import type { LogInstance } from "../../types";

export default async function nftData(
Expand All @@ -14,9 +19,21 @@ export default async function nftData(
const getNftTokenMetaData = async (contract: string, tokenId: bigint) => {
const nftContract = await provider.contract.at<NFTContractType>(contract);

const tokenMetaData = await (
await nftContract.storage()
).tokens.token_metadata.get(tas.nat(tokenId.toString()));
let tokenMetaData: {
token_id: nat;
token_info: MMap<string, bytes>;
};

try {
tokenMetaData = await (
await nftContract.storage()
).tokens.token_metadata.get(tas.nat(tokenId.toString()));
} catch (ex) {
tokenMetaData = await (await nftContract.storage()).token_metadata.get(
tas.nat(tokenId.toString()),
);
}

const metaDataInHex = tokenMetaData.token_info.get("");
return bytesToString(metaDataInHex);
};
Expand Down

0 comments on commit 71f18ca

Please sign in to comment.