Function: getMetadataIdForTokenId()
This function returns the Metadata ID for a specific token ID. Returns -1 if not found.
getMetadataIdForTokenId<
T>(tokenId,tokenMetadata):bigint|-1|T
Defined in: packages/bitbadgesjs-sdk/src/api-indexer/metadata/metadataIds.ts:40
This function returns the Metadata ID for a specific token ID. Returns -1 if not found.
Type Parameters
T
T extends NumberType
Parameters
tokenId
T
tokenMetadata
TokenMetadata<T>[]
Returns
bigint | -1 | T
Remarks
The token metadata array contains URI-to-token mappings, as returned by collection.getTokenMetadata().
These helpers use the mappings rather than the fetched metadata JSON.
Examples
import { getMetadataIdForTokenId, TokenMetadata } from 'bitbadges';
const tokenMetadata = [
new TokenMetadata<bigint>({
uri: 'https://example.com/{id}.json',
customData: '',
tokenIds: [{ start: 100n, end: 102n }]
})
];
const result = getMetadataIdForTokenId(101n, tokenMetadata);
console.log(result); // 2nUse the token metadata already loaded on a collection.
import { getMetadataIdForTokenId, type BitBadgesCollection } from 'bitbadges';
declare const collection: BitBadgesCollection<bigint>; // fetched through BitBadgesAPI
const result = getMetadataIdForTokenId(101n, collection.getTokenMetadata());