Basic Usage
Catalog

Catalog

Writing operations

  1. Adding parts
  2. Managing equippable addresses
    1. Adding equippable addresses
    2. Setting equippable addresses
    3. Resetting equippable addresses
    4. Setting equippable to all

Add parts

Parts can be added individually or in batches. In both cases you need to use an IntakeStruct struct which consists of a partId and a nested Part struct. The Part struct consists of the following fields: itemType, z, equippableAddresses and metadataURI.

  • Parts can have itemType either Slot or Fixed. Slots are meant to receive equipments from child NFTs, whereas Fixed are used to compose the final NFT.
  • The z field is used to specify the z-index which the part should be rendered at. The higher the z value, the more in the front the part will be rendered.
  • The equippableAddresses field is used to specify which collections can be equipped into the part. These can be later modified using the Manage equippable addresses methods.
  • The metadataURI field is used to specify the metadata URI of the part. See Fixed Parts and Slot Parts Metadata for more information.
const SLOT_PART_TYPE = 1;
const FIXED_PART_TYPE = 2;
 
// Single part
const intakeStruct = {
    partId: 1,
    part: {
        itemType: SLOT_PART_TYPE,
        z: 1,
        equippable: ['0x...'],
        metadataURI: 'ipfs://...'
    }
}
await catalog.addPart(intakeStruct)
 
// Multiple parts
const partList = [
    {
        partId: 1,
        part: {
            itemType: SLOT_PART_TYPE,
            z: 1,
            equippable: ['0x...'],
            metadataURI: 'ipfs://fallback'
        }
    },
    {
        partId: 2,
        part: {
            itemType: FIXED_PART_TYPE,
            z: 2,
            equippable: [],
            metadataURI: 'ipfs://composablePart'
        }
    },
    {
        partId: 3,
        part: {
            itemType: FIXED_PART_TYPE,
            z: 3,
            equippable: [],
            metadataURI: 'ipfs://composablePart'
        }
    }
]
await catalog.addPartList(partList)

Manage equippable addresses

There are multiple methods to manage the equippable addresses of a part. You can add, set or reset the equippable addresses of a part. You can also set a part as equippable to all.

Add equippable addresses

Used to add multiple equippable addresses. This method is additive, meaning that it will add the new addresses to the existing list of equippable addresses. It will unset the equippable to all flag, if it was set.

const partId = 1
const equippableAddresses = ['0x...']
await catalog.addEquippableAddresses(partId, equippableAddresses)

Set equippable addresses

Used to set the equippable addresses of a part. This method will overwrite the existing list of equippable addresses and unset the equippable to all flag, if it was set.

const partId = 1
const equippableAddresses = ['0x...']
await catalog.setEquippableAddresses(partId, equippableAddresses)

Reset equippable addresses

Used to reset the equippable addresses of a part. This method will remove all of the existing equippable addresses and unset the equippable to all flag, if it was set.

const partId = 1
await catalog.resetEquippableAddresses(partId)

Set equippable to all

Used to set the equippable to all flag of a part. This method will allow any collection to be equipped into the part. The flag is reset if any of these methods is called: Set equippable addresses, Add equippable addresses, Reset equippable addresses.

const partId = 1
await catalog.setEquippableToAll(partId)

Reading operations

  1. Getting parts
  2. Checking if equippable
  3. Checking if equippable to all
  4. Getting Metadata URI
  5. Getting Type

Get parts

Used to retrieve a Part with id partId. You can also retrieve multiple parts at the same time.

const partId = 1
const part = await catalog.getPart(partId)
// part = {
//     itemType: 1,
//     z: 1,
//     equippable: ['0x...'],
//     metadataURI: 'ipfs://...'
// }
 
const partIds = [1, 2]
const parts = await catalog.getParts(partIds)
// parts = [
//     {
    //         itemType: 1,
    //         z: 1,
    //         equippable: ['0x...'],
    //         metadataURI: 'ipfs://...'
    //     },
    //     {
    //         itemType: 2,
    //         z: 2,
    //         equippable: [],
    //         metadataURI: 'ipfs://...'
    //     }
    // ]

Check if Equippable

Used to check whether the given address is allowed to equip the desired part.

const partId = 1
const targetAddress = '0x...'
const isEquippable = await catalog.checkIsEquippable(partId, targetAddress)
// isEquippable = true|false

Check if Equippable to all

Used to check if any child can be equipped into the part.

const partId = 1
const isEquippableToAll = await catalog.checkIsEquippableToAll(partId)
// isEquippableToAll = true|false

Get Metadata URI

Used to return the metadata URI of the associated Catalog. See Catalog Metadata for more information.

const metadataURI = await catalog.getMetadataURI()
// metadataURI = 'ipfs://...'

Get Type

Used to return the itemType of the associated Catalog.

const itemType = await catalog.getType()
// itemType = 'image/gif'