Skip to main content

Deploying a Candy Machine

Apart from the launch command, discussed in the Quick Start section above, Sugar provide commands to manage the whole process of deployment of a Candy Machine, from the validation of assets to withdrawing funds and closing a Candy Machine account.

In this section we will cover the commands involved in deploying a Candy Machine in the order that they should be executed.

Preparing Your Assets

The preparation of the assets is similar to the instructions provided in the Candy Machine v2 documentation. By default, Sugar loads media/metadata files from an assets folder in the directory where the command has been executed, but the name of the folder can be specified as a command-line parameter.

Screen Shot 2022-04-29 at 10 50 00 AM

Example image of how your asset folder should look.

1. create-config

By default, Sugar looks for a config.json file in the current directory to load the Candy Machine configuration โ€” the configuration file name can be specified with a -c or --config option.

You can either create this file manually, following the instructions above, or use the create-config command:

sugar create-config

Executing the command starts an interative process consisting in a sequence of prompts to gather information about all configuration options. At the end of it, a configuration file is saved (default to config.json) or its content is displayed on screen. To specify a custom file name, use the option -c:

sugar create-config -c my-config.json

2. validate

The validate command is used to check that all files in the assets folder are in the correct format:

sugar validate

if your assest are in a folder named assets or:

sugar validate <ASSETS_DIR>

to specify a custom asset <ASSETS DIR> folder name.

Note: It is important to validate your assets before the upload to avoid having to repeat the upload process.

3. upload

The upload command uploads assets to the specified storage and creates the cache file for the Candy Machine:

sugar upload

if your assest are in a folder named assets or:

sugar upload <ASSETS DIR>

There is also the option to specify the path for the configuration file with the -c option (default config.json) and the name of the cache file with the option --cache (default cache.json).

The upload command can be resumed (re-run) at any point in case the upload is not completed successfully โ€” only files that have not yet being uploaded are processed. It also automatically detects when the content of media/metadata files change and re-uploads them, updating the cache file accordingly. In other words, if you need to change a file, you only need to copy the new (modified) file to your assets folder and re-run the upload command. There is no need to manually edit the cache file.

4. deploy

Once all assets are uploaded and the cache file is successfully created, you are ready to deploy your items to Solana:

sugar deploy

The deploy command will write the information of your cache file to the Candy Machine account on-chain. This effectively creates the Cancy Machine and displays its on-chain ID โ€” use this ID to query its information on-chain using an explorer. You can specify the path for the configuration file with the -c option (default config.json) and the name of the cache file with the option --cache (default cache.json) in case you are not using the default names.

After a succesful deploy, the Candy Machine is ready to be minted according to its goLiveDate and whitelistMintSettings.

Note: The authority wallet (the one used to create the Candy Machine) can mint bypassing the goLiveDate setting.

5. verify

The verify command checks that all items in your cache file have been successfully written on-chain:

sugar verify

if you are using the default cache file name (cache.json) or:

sugar verify --cache <CACHE>

to specify a different cache file path. If you deploy has been succesfully, the verification return no errors. At this point, you can set up your minting webpage to allow your community the chance to mint.

Other Commands

Sugar includes other commands to manage a Candy Machine.

mint

The mint command mints NFTs from a Candy Machine from the command-line.

sugar mint

if you are using the default cache file name (cache.json) or:

sugar mint --cache <CACHE>

to specify a different cache file path. You can specify the number of NFTs to mint using the option -n:

sugar mint -n 10

The above command will mint 10 NFTs from the Candy Machine.

Note: It is not possible to mint tokens from the command line if you have gatekeeper settings enabled. If you would like to mint tokens, update the goLiveDate to null and temporarily disable the gatekeeper settings.

show

The show command displays the on-chain config of an existing candy machine:

sugar show <CANDY MACHINE>

where the <CANDY MACHINE> is the Candy Machine ID โ€” the ID given by the deploy command.

update

The update command is used to modify the current configuration of a Candy Machine. Most configuration settings can be updated in a CMv2 with a single command, with the exception of:

  • number of items in the Candy Machine can only be updated when hiddenSettings are being used;
  • switching to use hiddenSettings is only possible if the number of items is equal to 0. After the switch, you will be able to update the number of items.

To update the configuration, modify your config.json (or equivalent) file and execute:

sugar update

if you are using the default cache file name (cache.json) and configuration file (config.json). Otherwise, use:

sugar update -c <CONFIG> --cache <CACHE>

where <CONFIG> is the path to the configuration file and <CACHE> is the path to the cache file.

You need to be careful when updating a live Candy Machine, since setting a wrong value will immediately affect its functionality.

withdraw

When the mint from a Candy Machine is complete, it is possible to recover the funds used to pay rent for the data stored on-chain. To initiate the withdraw:

sugar withdraw <CANDY MACHINE>

where the <CANDY MACHINE> is the Candy Machine ID โ€” the ID given by the deploy command. It is possible to withdraw funds from all Candy Machines associated with the current keypair:

sugar withdraw

or list all Candy Machines and their associated funds from the current keypair:

sugar withdraw --list

You should not withdraw the rent of a live Candy Machine, as the Candy Machine will stop working when you drain its account.

Further Reading

The Candy Machine v2 documentation provides a more detailed explanation of each step of the deploy of a Candy Machine. Although there a differences in Sugar commands, the overall process is similar.