Skip to main content

Grouping

Assets can be part of an on-chain group (collection). A group asset is created using the Grouping extension, which specify the maximum size of the group (or indicates that the group has no upper limit) and its current size. Member assets of a group point to the group asset in their group account field.

The group extension can be added to an asset either at creation time or after. It can also be removed as long as the group is empty (size equal to 0).

The extension consists of:

Creating a Group

The Grouping extension is used to create group assets. The extension can be added using either the allocate, create or update instructions.

import { allocate, grouping } from '@nifty-oss/asset';

await allocate(umi, {
asset,
payer,
extension: grouping(10),
}).sendAndConfirm(umi);

Fetching a Group

A group is an asset with the Grouping extension. Given an asset account, it is possible to retrieve the grouping extension to determine whether the asset represents a group or not. Note that not all assets might have the extension, therefore it is necessary to assert if the extension was found.

import {
ExtensionType,
fetchAsset,
getExtension
} from '@nifty-oss/asset';

const asset = await fetchAsset(umi, address);
const grouping = getExtension(asset, ExtensionType.Grouping);

if (grouping) {
console.log("size=" + grouping.size);
}