Actions

Creating a Core Candy Machine

Note: Before creating the Candy Machine, ensure that all assets intended for loading are fully prepared and uploaded to a decentralized storage solution. If you're unsure how to proceed, follow to this guide: Preparing the Candy Machine Assets

Additionally, you'll need a Core Collection (new or existing) where all the assets created by the Candy Machine will be included. If you're unfamiliar with creating a Core Collection, follow this guide: Create a Core Collection

Creating a Candy Machine

All arguments passed in the create function define the behavior, ownership, and configuration of the Candy Machine.

Below is a detailed breakdown of each argument, including required and optional parameters:

NameTypeDescription
candyMachinesignerA newly generated keypair/signer used to create the Core Candy Machine.
authorityPda (optional)publicKeyPDA used to verify minted assets to the collection. Auto-calculated if left undefined.
authority (optional)publicKeyThe wallet/public key that will be the authority over the Core Candy Machine.
payer (optional)signerWallet that pays for the transaction and rent costs. Defaults to the signer.
collectionpublicKeyThe collection into which the Core Candy Machine will create assets.
collectionUpdateAuthoritysignerSigner required to approve a delegate verifying created assets in the collection.
itemsAvailablenumberNumber of items being loaded into the Core Candy Machine.
isMutablebooleanBoolean indicating whether the assets are mutable upon creation.
configLineSettings(optional)LinkConfiguration settings for asset lines.
hiddenSettings (optional)LinkOptional settings for hiding asset information.
guards (optional)LinkOptional settings for adding Candy Guards.

When creating a Candy Machine, there are different configurations that can modify its behavior. The most important ones include:

  • ConfigLineSettings: Reduces the space required for the Candy Machine by not storing identical name and URI prefixes linked to all the assets.
  • HiddenSettings: Allows minting the same asset to all purchasers while storing a hash of data that validates each updated/revealed NFT correctly.
  • Guards: Adds specific Candy Guards to the Candy Machine.

If no additional behavior or configuration is required, the code to create a Candy Machine will look like this:

Create a Core Candy Machine

// Create the Candy Machine.
import { create } from '@metaplex-foundation/mpl-core-candy-machine'
import { generateSigner } from '@metaplex-foundation/umi'

const candyMachine = generateSigner(umi)

const createIx = await create(umi, {
  candyMachine,
  collection: collectionMint.publicKey,
  collectionUpdateAuthority: umi.identity,
  itemsAvailable: 1000,
  authority: umi.identity.publicKey,
})

await createIx.sendAndConfirm(umi)

with Config Line Settings

Config Line Settings is an optional feature that helps reduce the Core Candy Machine's rent cost by minimizing stored asset data.

This is done by storing common prefix for Assets and URI once, and allowing then the Core Candy Machine to append unique indexes automatically.

For example if your assets are named Example Asset #1 through Example Asset #1000, storing the prefix Example Asset # once and appending numbers from 1 to 1000 saves storing the same prefix 1000 times, reducing storage by 15,000 bytes.

The same approach applies to the URI prefix, further lowering rent costs.

To use it, we'll need to create a specific struct. Below is a detailed breakdown of each argument present in the ConfigLineSettings Struct:

FieldTypeDescription
prefixNamestringStores the name prefix of the NFTs. The minted index is appended to create unique names.
nameLengthnumberMaximum length of the NFT name excluding the prefix.
prefixUristringBase URI of the metadata, excluding the unique identifier.
uriLengthnumberMaximum length of the URI excluding the base prefixUri.
isSequentialbooleanIndicates whether to use sequential or random minting.

Here is an example of creating a Core Candy Machine with configLineSettings applied:

Create a Core Candy Machine with configLineSettings

import { create } from '@metaplex-foundation/mpl-core-candy-machine'

const candyMachine = generateSigner(umi)

const coreCollection = publicKey('11111111111111111111111111111111')

const createIx = await create(umi, {
  // ...
  configLineSettings: some({
    prefixName: 'Example Asset #',
    nameLength: 4,
    prefixUri: 'https://example.com/metadata/',
    uriLength: 9,
    isSequential: false,
  }),
})

await createIx.sendAndConfirm(umi)

with Hidden Settings

Hidden Settings is an optional feature that mints the same asset to all buyers, allowing creators to reveal the actual assets at a later time.

Note: This feature also supports printing Core Editions when used with the Edition Guard.

To ensure the revealed NFT data hasn’t been manipulated (such as moving rare assets to specific holders), creators must submit and save a hash that links each asset's URI with its corresponding number during the creation of the Candy Machine.

This can be done with the following code:

import crypto from 'crypto'

const revealData = [
  { name: 'Nft #1', uri: 'http://example.com/1.json' },
  { name: 'Nft #2', uri: 'http://example.com/2.json' },
  { name: 'Nft #3', uri: 'http://example.com/3.json' },
]

const string = JSON.stringify(revealData)
const hash = crypto.createHash('sha256').update(string).digest()

console.log(hash)

To use it, we'll need to create a specific struct. Below is a detailed breakdown of each argument present in the HiddenSettings Struct:

FieldTypeDescription
namestringThe name applied to all minted assets. Supports special variables like $ID$ and $ID+1$.
uristringThe URI applied to all minted assets.
hashUint8ArrayCryptographic hash used to verify that the revealed NFTs match the originally minted data.

Here is an example of creating a Core Candy Machine with hiddenSettings applied:

Create a Core Candy Machine with hiddenSettings

import { create } from '@metaplex-foundation/mpl-core-candy-machine'
import crypto from "crypto";

const candyMachine = generateSigner(umi)

const revealData = [
  { name: 'Nft #1', uri: 'http://example.com/1.json' },
  { name: 'Nft #2', uri: 'http://example.com/2.json' },
  { name: 'Nft #3', uri: 'http://example.com/3.json' },
]

const string = JSON.stringify(revealData)
const hash = crypto.createHash('sha256').update(string).digest()

const createIx = await create(umi, {
  // ...
  hiddenSettings: {
    name: "Hidden Asset",
    uri: "https://example.com/hidden-asset.json",
    hash,
  }
})

await createIx.sendAndConfirm(umi)

with Guards

Candy Guards is an optional feature that adds extra functionalities to a Core Candy Machine.

To enable guards, pass the some() attribute along with the required data for each specific guard. Any guard set to none() or not provided will be disabled by default.

If you want to learn more about what Candy Guards are available, refer to this: Candy Guards Overview

Here's a list of all the Candy Guards available and the individual attributes:

Here is an example of creating a Core Candy Machine with guards applied:

Create a Core Candy Machine with guards

import { some, sol, dateTime } from '@metaplex-foundation/umi'

const createIx = await create(umi, {
  // ...
  guards: {
    botTax: some({ lamports: sol(0.01), lastInstruction: true }),
    solPayment: some({ lamports: sol(1.5), destination: treasury }),
    startDate: some({ date: dateTime('2023-04-04T16:00:00Z') }),
    // ...
  },
})

await createIx.sendAndConfirm(umi)
Previous
Getting Started