Core

Features

Managing Collections

What are Collections?

Collections are a group of Assets that belong together, part of the same series, or group. In order to group Assets together, we must first create a Collection Asset whose purpose is to store any metadata related to that collection such as collection name and collection image. The Collection Asset acts as a front cover to your collection and can also store collection wide plugins.

The data that is stored and accessible from the Collection Asset is as follows;

AccountsDescription
keyThe account key discriminator
updateAuthorityThe authority of the new asset.
nameThe collection name.
uriThe uri to the collections off-chain metadata.
num mintedThe number of assets minted in the collection.
current sizeThe number of assets currently in the collection.

Creating a Collection

To create a Core Collection you can use the CreateCollection instruction like this:

Creating a Simple Collection

The following snippet creates a simple collection without Plugins or anything special.

Create a MPL Core Collection

import { generateSigner } from '@metaplex-foundation/umi'
import { createCollection } from '@metaplex-foundation/mpl-core'
const collectionSigner = generateSigner(umi)
await createCollection(umi, {
collection: collectionSigner,
name: 'My Collection',
uri: 'https://example.com/my-collection.json',
})

Creating a Collection with Plugins

The following snippet creates a collection with the Royalties Plugin attached. You can attach additional plugins as described here.

Create a MPL Core Collection with Plugin

import { generateSigner, publicKey } from '@metaplex-foundation/umi'
import { createCollection, ruleSet } from '@metaplex-foundation/mpl-core'
const collectionSigner = generateSigner(umi)
const creator1 = publicKey('11111111111111111111111111111111')
const creator2 = publicKey('22222222222222222222222222222222')
await createCollection(umi, {
collection: collectionSigner,
name: 'My NFT',
uri: 'https://example.com/my-nft.json',
plugins: [
{
type: 'Royalties',
basisPoints: 500,
creators: [
{
address: creator1,
percentage: 20,
},
{
address: creator2,
percentage: 80,
},
],
ruleSet: ruleSet('None'), // Compatibility rule set
},
],
}).sendAndConfirm(umi)

Fetch a Collection

To fetch a collection the following function can be used:

Fetch a collection

import { fetchCollectionV1 } from '@metaplex-foundation/mpl-core'
import { publicKey } from '@metaplex-foundation/umi'
const collectionId = publicKey('11111111111111111111111111111111')
const collection = await fetchCollection(umi, collectionId)
console.log(collection)

Updating a Collection

To update the data of a Core Collection use the UpdateCollection instruction. For example, you use this instruction to change the name of a collection.

Updating a Collection

import { publicKey } from '@metaplex-foundation/umi'
import { updateCollection } from '@metaplex-foundation/mpl-core'
const collectionAddress = publicKey('1111111111111111111111111111111')
await updateCollection(umi, {
collection: collectionAddress,
name: 'my-nft',
uri: 'https://exmaple.com/new-uri',
}).sendAndConfirm(umi)

Updating a Collection Plugin

If you want to change the behaviour of a plugin that is attached to a Core Collection you may want to use the updateCollectionPlugin instruction.

Updating a Collection Plugin

import { publicKey } from '@metaplex-foundation/umi'
import { updateCollectionPlugin, ruleSet } from '@metaplex-foundation/mpl-core'
const collectionAddress = publicKey('1111111111111111111111111111111')
const newCreator = publicKey('5555555555555555555555555555555')
await updateCollectionPlugin(umi, {
collection: collectionAddress,
plugin: {
type: 'Royalties',
basisPoints: 400,
creators: [{ address: newCreator, percentage: 100 }],
ruleSet: ruleSet('None'),
},
}).sendAndConfirm(umi)