Actions

Updating a Candy Machine

Updating the Data

Below is a breakdown of the arguments in the data structure that can be modified:

AttributeType
itemsAvailablenumber
isMutableboolean
configLineSettingsLink
hiddenSettingsLink

Here is an example of how to update a Core Candy Machine:

Updating a Core Candy Machine

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

// Publickey of the candyMachine to update
const candyMachine = publicKey('11111111111111111111111111111111')

await updateCandyMachine(umi, {
  candyMachine,
  data: {
    itemsAvailable: 3333;
    isMutable: true;
    configLineSettings: none();
    hiddenSettings: none();
}
}).sendAndConfirm(umi)

Updating the Authority

To update the authority of the Candy Machine to a new address, use the setCandyMachineAuthority() function and pass the new address in the newAuthority field.

Here's an example of how to update the authority of a Candy Machine:

Update Authority of Core Candy Machine

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

const candyMachine = publicKey('11111111111111111111111111111111')
const newAuthority = publicKey('22222222222222222222222222222222')

await setMintAuthority(umi, {
  candyMachine,
  mintAuthority: newAuthority,
}).sendAndConfirm(umi)

Updating the Mint Authority

To update the mint authority of the Candy Machine to a new address, use the setMintAuthority() function and pass the new address in the mintAuthority field.

Note: If the Candy Machine has any guards, the mintAuthority field will be assigned to that account. By changing the mintAuthority, you're disabling the Candy Guard mechanism.

Here's an example of how to update the mint authority of a Candy Machine:

Update Mint Authority of Core Candy Machine

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

const candyMachine = publicKey('11111111111111111111111111111111')
const newAuthority = publicKey('22222222222222222222222222222222')

await setMintAuthority(umi, {
  candyMachine,
  mintAuthority: newAuthority,
}).sendAndConfirm(umi)

Updating the Guards

Updating the Guards, works similarly to the way we set them when we created the Candy Machine. To enable guards, provide their settings; to disable them, set them to none() or leave them out.

Note: The entire guards object is replaced during the update, so include all guards you want to keep, even if their settings remain unchanged. Consider fetching the current guard settings before updating to avoid overwriting unintended fields.

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

Here is an example of updating the guards from an existing Candy Machine:

Update the Guards of a Core Candy Machine

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

const candyGuard = await fetchCandyGuard(umi, candyMachine.mintAuthority)

await updateCandyGuard(umi, {
  candyGuard: candyGuard.publicKey,
  guards: {
    ...candyGuard.guards,
    botTax: none(),
    solPayment: some({ lamports: sol(3), destination: treasury }),
  },
})

Associating and Dissociating Guard accounts manually

The create function that we used previously already takes care of creating and associating a brand new Candy Guard account for every Candy Machine account created.

However, it is important to note that Core Candy Machines and Core Candy Guards can be created and associated in different steps by creating the two accounts separately and associate/dissociate them manually after using the wrap() and unwrap() function.

Here is an example of associating and dissociating the guards from an existing Candy Machine:

Associate and dissociate guards from a Candy Machine

import {
  some,
  percentAmount,
  sol,
  dateTime
} from '@metaplex-foundation/umi'
import {
  createCandyMachine,
  createCandyGuard,
  findCandyGuardPda,
  wrap,
  unwrap
} from '@metaplex-foundation/mpl-core-candy-machine'

// Create a Candy Machine without a Candy Guard.
const candyMachine = generateSigner(umi)

await createCandyMachine({
  candyMachine,
  collection: collectionMint.publicKey,
  collectionUpdateAuthority: umi.identity,
  itemsAvailable: 1000,
  authority: umi.identity.publicKey,
}).sendAndConfirm(umi)

// Create a Candy Guard.
const base = generateSigner(umi)
const candyGuard = findCandyGuardPda(umi, { base: base.publicKey })

await createCandyGuard({
  base,
  guards: {
    botTax: { lamports: sol(0.01), lastInstruction: false },
    solPayment: { lamports: sol(1.5), destination: treasury },
    startDate: { date: dateTime('2022-10-17T16:00:00Z') },
  },
}).sendAndConfirm(umi)

// Associate the Candy Guard with the Candy Machine.
await wrap({
  candyMachine: candyMachine.publicKey,
  candyGuard,
}).sendAndConfirm(umi)

// Dissociate them.
await unwrap({
  candyMachine: candyMachine.publicKey,
  candyGuard,
}).sendAndConfirm(umi)
Previous
Loading Items in a Candy Machine