Skip to content

This function returns the Metadata IDs for a specific token URI. Returns an empty array if not found.

getMetadataIdsForUri<T>(uri, tokenMetadata): T[]

Defined in: packages/bitbadgesjs-sdk/src/api-indexer/metadata/metadataIds.ts:96

This function returns the Metadata IDs for a specific token URI. Returns an empty array if not found.

Type Parameters

T

T extends NumberType

Parameters

uri

string

tokenMetadata

TokenMetadata<T>[]

Returns

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

ts
import { getMetadataIdsForUri, TokenMetadata } from 'bitbadges';
const tokenMetadata = [
  new TokenMetadata<bigint>({
    uri: 'https://example.com/{id}.json',
    customData: '',
    tokenIds: [{ start: 100n, end: 102n }]
  })
];
const result = getMetadataIdsForUri('https://example.com/101.json', tokenMetadata);
console.log(result); // [2n]

Use the token metadata already loaded on a collection.

ts
import { getMetadataIdsForUri, type BitBadgesCollection } from 'bitbadges';
declare const collection: BitBadgesCollection<bigint>; // fetched through BitBadgesAPI
const result = getMetadataIdsForUri('https://example.com/101.json', collection.getTokenMetadata());

Edit this page on GitHub