Class BitBadgesCollection<T>

BitBadgesCollection is the type for collections returned by the BitBadges API. It extends the base CollectionDoc type and adds additional accompanying Docrmation such as metadata, activity, balances, preferred chain, etc.

Type Parameters

Hierarchy (view full)

Implements

Constructors

Properties

Methods

checkCanArchiveCollection checkCanDeleteCollection checkCanUpdateBadgeMetadata checkCanUpdateCollectionApprovals checkCanUpdateCollectionMetadata checkCanUpdateCustomData checkCanUpdateManager checkCanUpdateOffChainBalancesMetadata checkCanUpdateStandards checkCanUpdateValidBadgeIds clone convert equals fetchAllForView fetchAndUpdate fetchBadgeBalances fetchMetadata fetchNextForView filterBadgesInCollection generateAliasForBadgeId getActivityView getApprovalTrackersView getBadgeActivity getBadgeBalanceInfo getBadgeBalances getBadgeIdRange getBadgeMetadata getBadgeMetadataDetails getBadgeMetadataTimelineValue getCollectionMetadata getCollectionMetadataDetails getCollectionMetadataTimelineValue getCurrentBadgeMetadata getCustomData getDefaultUserBalance getIsArchived getManager getMaxBadgeId getMerkleChallengesView getMintCollectionApprovals getNonMintCollectionApprovals getNumberFieldNames getOffChainBalancesMetadata getOwnersForBadge getOwnersView getRefreshStatus getStandards getUnhandledCollectionApprovals getView getViewBookmark getViewPagination isRedundantRequest mustGetBadgeBalanceInfo mustGetBadgeBalances pruneMetadataToFetch prunePayload refresh setBadgeMetadataForTimes setCollectionMetadataForTimes toJson toJsonString updateWithNewResponse validateBadgeMetadataUpdate validateCollectionApprovalsUpdate validateCustomDataUpdate validateIsArchivedUpdate validateManagerUpdate validateOffChainBalancesMetadataUpdate validatePermissionUpdate validatePermissionsUpdate validateStandardsUpdate viewHasMore FetchAndInitialize FetchAndInitializeBatch FilterBadgesInCollection GetBadgeActivity GetBadgeBalanceByAddress GetCollections GetOwnersForBadge GetRefreshStatus RefreshMetadata

Constructors

Properties

_docId: string

A unique stringified document ID

_id?: string

A unique document ID (Mongo DB ObjectID)

activity: TransferActivityDoc<T>[]

The fetched activity for this collection. Returned collections will only fetch the current page. Use the pagination to fetch more. To be used in conjunction with views.

aliasAddress: string

The alias BitBadges address for the collection

approvalTrackers: ApprovalTrackerDoc<T>[]

The fetched approval trackers for this collection. Returned collections will only fetch the current page. Use the pagination to fetch more. To be used in conjunction with views.

badgeMetadataTimeline: BadgeMetadataTimelineWithDetails<T>[]

The badge metadata timeline for this collection, with off-chain metadata populated.

balancesType:
    | "Standard"
    | "Off-Chain - Indexed"
    | "Non-Public"
    | "Off-Chain - Non-Indexed"

The type of balances (i.e. "Standard", "Off-Chain - Indexed", "Non-Public, "Off-Chain - Non-Indexed")

claims: ClaimDetails<T>[]

Details about any off-chain claims for this collection. Only applicable when outsourced to BitBadges.

collectionApprovals: CollectionApprovalWithDetails<T>[]

The collection approvals for this collection, with off-chain metadata populated.

collectionId: T

The collection ID

collectionMetadataTimeline: CollectionMetadataTimelineWithDetails<T>[]

The collection metadata timeline for this collection, with off-chain metadata populated.

collectionPermissions: CollectionPermissionsWithDetails<T>

The collection permissions for this collection, with off-chain metadata populated.

createdBlock: T

The block number when this collection was created

createdBy: string

The BitBadges address of the user who created this collection

createdTimestamp: T

The timestamp when this collection was created (milliseconds since epoch)

customDataTimeline: CustomDataTimeline<T>[]

The custom data timeline

defaultBalances: UserBalanceStoreWithDetails<T>

The default balances for users upon genesis, with off-chain metadata populated.

isArchivedTimeline: IsArchivedTimeline<T>[]

The is archived timeline

managerTimeline: ManagerTimeline<T>[]

The manager timeline

merkleChallenges: MerkleChallengeDoc<T>[]

The fetched merkle challenges for this collection. Returned collections will only fetch the current page. Use the pagination to fetch more. To be used in conjunction with views.

nsfw?: {
    badgeIds: UintRangeArray<T>;
    reason: string;
}

The badge IDs in this collection that are marked as NSFW.

offChainBalancesMetadataTimeline: OffChainBalancesMetadataTimeline<T>[]

The off-chain balances metadata timeline

The fetched owners of this collection. Returned collections will only fetch the current page. Use the pagination to fetch more. To be used in conjunction with views.

reported?: {
    badgeIds: UintRangeArray<T>;
    reason: string;
}

The badge IDs in this collection that have been reported.

reservedMap?: MapDoc<T>

The reserved map for the account. This is created and managed on-chain through the x/maps module.

standardsTimeline: StandardsTimeline<T>[]

The standards timeline

updateHistory: UpdateHistory<T>[]

The update history of this collection

validBadgeIds: UintRangeArray<T>

Valid badge IDs for the collection

views: {
    [viewId: string]: {
        ids: string[];
        pagination: PaginationInfo;
        type: string;
    } | undefined;
}

The views for this collection and their pagination Doc. Views will only include the doc _ids. Use the pagination to fetch more. To be used in conjunction with activity, announcements, reviews, owners, merkleChallenges, and approvalTrackers. For example, if you want to fetch the activity for a view, you would use the view's pagination to fetch the doc _ids, then use the corresponding activity array to find the matching docs.

Methods

  • Compares this object's fields to another object's fields for equality. Equality is determined by comparing the JSON representations of the objects.

    If normalizeNumberTypes is true, then all number types will be compared as strings (i.e. "1n" === "1" === 1). Else, they will be compared as their native types (i.e. 1n !== 1 !== "1").

    Type Parameters

    Parameters

    • other: undefined | null | CustomType<U>
    • OptionalnormalizeNumberTypes: boolean

    Returns boolean

  • Fetches the entire view (all pages) for a specific view. This will update the current collection with the new response information.

    There is a 1 second delay between each page fetch to prevent rate limiting.

    Parameters

    Returns Promise<void>

  • Fetches the next page for a specific view. This will update the current collection with the new response information (handling paginations).

    If the view has no more pages, this will do nothing.

    Parameters

    Returns Promise<void>

  • Gets the badge balance document for a specific address from the cached owners array. Returns undefined if not fetched yet. The balance document includes the balances, outgoing approvals, and other details. Use getBadgeBalances to only get the balances.

    Parameters

    • address: string

    Returns undefined | BalanceDocWithDetails<T>

    This does not fetch the balance from the API. It only returns the cached balance. To fetch the balance, this can either be done directly, or if the collection balances are indexable then the balances can also be fetched via the views and / or the other fetch methods.

    const collection: BitBadgesCollection<bigint> = { ... }
    const address = 'bb1...'
    const balance = collection.getBadgeBalance(address)
    console.log(balance?.balances)
    console.log(balance?.outgoingApprovals)
  • Gets the badge balances for a specific address from the cached owners array. Returns undefined if not fetched yet. This returns the balances only, not the other details. Use getBadgeBalanceInfo to get the other details for a user balance store (approvals, etc.).

    Parameters

    • address: string

    Returns undefined | BalanceArray<T>

    This does not fetch the balance from the API. It only returns the cached balance. To fetch the balance, this can either be done directly, or if the collection balances are indexable (i.e. balances type is anything but Off-Chain - Non-Indexed), then the balances can also be fetched via the views and / or the other fetch methods.

    const collection: BitBadgesCollection<bigint> = { ... }
    const address = 'bb1...'
    const balances = collection.getBadgeBalances(address)
    console.log(balances)
  • Get the metadata for a specific badge ID. This is the fetched metadata, not the timeline values.

    This only returns the metadata object (name, image, etc.) and not the URI or other accompanying details. For those, use getBadgeMetadataDetails.

    Parameters

    • badgeId: T

    Returns undefined | Metadata<T>

    const collection: BitBadgesCollection<bigint> = { ... }
    const badgeId = 123n
    const metadata = collection.getBadgeMetadata(badgeId)
    const metadataImage = metadata.image
  • Get the cached collection metadata. This is the fetched metadata, not the timeline values.

    Returns undefined | Metadata<T>

    const collection: BitBadgesCollection<bigint> = { ... }
    const metadata = collection.getCollectionMetadata()
    const metadataImage = metadata.image
  • Gets the maximum badge ID for the collection. Checks both the circulating supplys + genesis default balances.

    Precondition: The Total balance must be fetched.

    Returns bigint

  • Returns the bookmark for a specific view. This is used to fetch the next page.

    Parameters

    • viewId: string

    Returns undefined | string

  • For a metadata fetch request, prune the request to only request the metadata that is not already fetched.

    Parameters

    Returns {
        doNotFetchCollectionMetadata: boolean;
        uris: string[];
    }

    • doNotFetchCollectionMetadata: boolean
    • uris: string[]
    const collection: BitBadgesCollection<bigint> = { ... }
    const metadataToFetch = collection.pruneMetadataToFetch({ badgeIds: [1n, 2n, 3n], uris: ['ipfs://...'] })
    console.log(metadataToFetch)
  • Updates the current collection with a new response from the API. If forceful is true, we fully overwrite the current collection with the new response. Else, we will append the new response to the current collection while handling duplicates, paginations, etc.

    Parameters

    Returns void

  • Validates if a single permission type is updated correctly. Cannot edit anything permanently frozen.

    This is validating the updatability of the permissions. To validate whether a permission is executable, use the checkCan* functions.

    Parameters

    Returns null | Error