The BadgeMetadataDetails type captures comprehensive details about the metadata of a badge. It contains fields such as badge IDs (ranges), associated metadata, a URI, and custom data. This is what is used via the cachedBadgeMetadata field from collection responses.
2. Removing Metadata for Specific Badge IDs
To delete metadata associated with specific badge IDs:
constcurrentMetadata:BadgeMetadataDetails<bigint>[] = [...]; // your current metadata arrayconstbadgeIdsToRemove=UintRangeArray.From([ { start:5n, end:10n }];const updatedMetadata =removeBadgeMetadata(currentMetadata, badgeIdsToRemove);console.log(updatedMetadata); // This will show metadata without the removed badge IDs.
3. Updating Metadata for Badges
If you wish to update specific badge metadata in the badge metadata details:
constcurrentMetadata:BadgeMetadataDetails<bigint>[] = [...]; // your current metadata arrayconstmetadataToUpdate:BadgeMetadataDetails<bigint> =newBadgeMetadataDetails<bigint>({ badgeIds: [{ start:7n, end:7n }], metadata: { /* your metadata details here */ }, uri:"http://new-metadata-url.com",//Or 'Placeholder' or something else customData:"Some custom information",});constnewMetadataArray=updateBadgeMetadata(currentMetadata, metadataToUpdate);console.log(newMetadataArray); // This will show the array with the updated metadata.
4. Fetch Metadata Details for a Specific Badge ID
To retrieve metadata details for a particular badge ID:
constbadgeIdToFetch=12n;constbadgeMetadataDetails=getMetadataDetailsForBadgeId(badgeIdToFetch, currentMetadata);console.log(badgeMetadataDetails); // This will display the metadata details for the specified badge ID.
5. Fetch Only the Metadata for a Specific Badge ID
To only retrieve the metadata (without the surrounding details) for a particular badge ID:
constbadgeIdToFetch=15n;constbadgeMetadata=getMetadataForBadgeId(badgeIdToFetch, currentMetadata);console.log(badgeMetadata); // This will show only the metadata for the given badge ID.
Conclusion
These functions provide a robust toolkit for managing badge metadata. Whether you're updating, fetching, or deleting metadata associated with badges, you have a systematic and structured approach available.