Passer au contenu principal

How to Deploy an NFT Collection on Solana Using Sugar (Candy Machine)

Mis à jour le
15 avril 2026

6 min de lecture

Sugar v1 is Deprecated

This guide uses Sugar v1 with Candy Machine V2, which is deprecated. For new NFT projects, see How to Launch an NFT Collection with Metaplex Core Candy Machine. This guide is for historic educational purposes only.

Aperçu

Are you ready to launch your NFT collection on Solana? Metaplex's new Candy Machine tool, Sugar, is the tool for you to launch in no time. Sugar, Metaplex's latest version of Candy Machine, comes with a few notable improvements: 

  • amélioration des performances de téléchargement
  • expérience utilisateur simplifiée 
  • gestion améliorée des erreurs

Ce que vous ferez

In this guide, you will create a new wallet using Solana CLI, airdrop some SOL, and deploy a Candy Machine on Solana's devnet using Sugar. You'll then deploy your Candy Machine to the web using Candy Machine UI. 

Ce dont vous aurez besoin

  • Nodejs installed (version 16.15 or higher)
  • CLI Solana installée
  • Extension Phantom Wallet ou Solflare installée 
  • Metaplex Sugar installed (**Legacy Version, V1.x **)
  • Un éditeur de texte
  • npm or yarn installed (We will be using yarn to initialize our project and install the necessary packages. Feel free to use npm instead if that’s your preferred package manager.)

Configurer votre projet

Créez un nouveau répertoire de projet dans votre terminal à l'aide de la commande suivante :

mkdir sugar-demo
cd sugar-demo

Installer Sugar

This guide assumes you are using a legacy version of Sugar, V1.x. (Candy Machine v2). If you are using a newer version, check out our guide here.

Installation sur Mac

In your terminal enter:

<(curl -sSf https://sugar.metaplex.com/install.sh)

Remarque : il se peut que vous deviez redémarrer votre terminal après l'installation.

Installation sous Windows

  1. Download the windows installer here.
  2. Lancez le programme d'installation en tant qu'administrateur (clic droit -->Exécuter en tant qu'administrateur). If you get a warning about an untrusted binary try clicking Plus d'informations et ensuite Courir quand même. Si cette option n'est pas disponible, procédez comme suit : 
    • Cliquez avec le bouton droit sur le fichier exécutable, puis sélectionnez « Propriétés ».
    •  If you trust the Metaplex developer team, check the Unblock button as show in the image below. This will allow you to run this binary on your computer since Microsoft does not trust it automatically.
    • Cliquez sur « Appliquer », puis sur « OK ».
    • Relancez le programme d'installation

Si tout fonctionne correctement, vous devriez voir quelque chose comme ceci :

Confirmation de la réussite de l'installation de Windows

Configurer un nouveau portefeuille

One of the cool new features of Sugar is that it will allow you to set your wallet and RPC configs using Solana CLI, so that you don't need to re-enter them in each of your sugar commands. 

Nous devons tout d'abord créer un nouveau portefeuille destiné spécifiquement aux tests sur le réseau de développement (devnet) à l'aide de la commande suivante :

solana-keygen new --outfile ./wallet.json

We can skip the password (by hitting Enter) as we will only use this wallet on devnet, so the funds are not important. We can confirm that the wallet we just generated is the wallet that the Solana CLI will use by running: 

Configuration de Solana définir --keypair ./wallet.json

Établir une connexion à votre RPC Quicknode

We will need to make sure our Solana CLI is connected to a node. You're welcome to use public nodes or deploy and manage your own infrastructure, however, if you'd like 8x faster response times you can leave the heavy lifting to us.


See why over 50% of projects on Solana choose Quicknode and sign up for free here.

Make sure to launch your node under the Solana Devnet and copy the HTTP link:

New Solana HTTP Endpoint

With your endpoint on the Solana Devnet setup, you can now run this command, substituting YOUR_QUICKNODE_URL with the HTTP URL you have copied:

Configuration de Solana définir --url VOTRE_URL_QUICKNODE

Now to fund your wallet you can run the command:

Airdrop Solana 1

If the command is successful you should see something like this:

Succès de l'airdrop

Vous pouvez également exécuter solde Solana dans votre terminal et vérifiez que le 1 SOL s'y trouve bien.

Préparer les actifs NFT

If you have used Candy Machine before, this process will be familiar. We need to create a .json file corresponding to each digital asset using a simple number format starting with 0 and increase sequentially, never skipping a number (e.g., 0.json maps to 0.png, then 1.json maps to 1.png). We can also create an optional collection.json and collection.png to enable Sugar to automatically create an on-chain collection. 

Metaplex propose un ensemble d'exemples de ressources que l'on peut télécharger et utiliser afin de garantir la cohérence. Vous pouvez modifier le fichier JSON pour y inclure les valeurs de votre choix, à condition qu'elles soient conformes au schéma JSON de l'URI.

Download the sample set and extract the contents to ./assets/ in your project directory (this is the default directory that Sugar will look for your files). 

Configurer la machine à bonbons

Create a new file, config.json in your root project folder: 

écho > config.json

Ouvrez le fichier et collez cette configuration : 

{
"price": 0.01,
"number": 10,
"symbol": "NB",
"sellerFeeBasisPoints": 500,
"gatekeeper": null,
"solTreasuryAccount": "YOUR_WALLET_ADDRESS",
"splTokenAccount": null,
"splToken": null,
"goLiveDate": "2022-07-24T00:00:00Z",
"endSettings": null,
"whitelistMintSettings": null,
"hiddenSettings": null,
"uploadMethod": "bundlr",
"awsS3Bucket": null,
"retainAuthority": true,
"isMutable": true,
"creators": [
{
"address": "YOUR_WALLET_ADDRESS",
"share": 100
}
]
}

REMARQUE : vous pouvez exécuter la commande « solana address » dans votre terminal pour obtenir l'adresse du portefeuille que vous venez de créer.

Now, we should be all set. If you're following along to this point you should have a directory structure like this: 

  • sugar-demo/wallet.json
  • sugar-demo/config.json
  • sugar-demo/assets/[0-9].png
  • sugar-demo/assets/[0-9].json
  • sugar-demo/assets/collection.png
  • sugar-demo/assets/collection.json

Sugar has a built in validation error that will let us check for any errors before we proceed. In terminal, run: 

vérification de la teneur en sucre

Validation de Sugar réussie

C'est parti ! Bravo. Construisons notre machine à bonbons. 

Create Candy Machine

Because we've set our RPC and wallet using Solana CLI and because we've saved our assets and config.json to Sugar's default directories, our commands will be quite simple! 

Téléchargez vos ressources

In your terminal enter:

téléchargement de sucre

Vous devriez voir quelque chose comme ça :

Téléchargement de Sugar réussi

Déployer un distributeur de bonbons

In your terminal enter:

déploiement de Sugar

Vous devriez voir quelque chose comme ça :

Succès du déploiement de Sugar

If you get a "Blockhash not found" error, try running the command again.

Make sure to store the Candy Machine ID provided in your terminal locally. We'll need this later.

Vérifier la machine à bonbons

Let's make sure everything has worked as we'd expected. In your terminal enter:

vérification du sucre

Vous devriez voir quelque chose comme ça :

Distributeur de bonbons certifié

Bravo !

Testez votre distributeur de bonbons

Try minting an NFT using sugar. In your terminal enter:

menthe sucrée

Vous devriez voir quelque chose comme ça : 

Sucre à la menthe : une réussite

Excellent! Let's create a mint page so we can share this project with the world!

Créer un site de frappe de pièces

For the easiest possible set up, we will be using the front end that Metaplex provides us, Candy Machine UI. 

From your project directory, in your terminal enter: 

git clone https://github.com/metaplex-foundation/candy-machine-ui ./candy-machine-ui/
cd candy-machine-ui

Rename the file .env.example to .env. After changing the file name, you can change the values in there to the following:

REACT_APP_CANDY_MACHINE_ID=<YOUR_CANDY_MACHINE_PUBKEY>
REACT_APP_SOLANA_NETWORK=devnet
REACT_APP_SOLANA_RPC_HOST=<YOUR_QUICKNODE_DEVNET_ENDPOINT>

If you don't remember your Candy Machine ID, you should be able to find it in cache.json in the program.candyMachine field. 

With all of that information plugged in, you can now save the file. From that candy-machine-ui folder, run the following commands:

yarn install
yarn start

Cela ouvrira un navigateur sur localhost:3000, où vous pourrez connecter votre portefeuille et créer un NFT. Vérifiez que votre portefeuille Phantom est bien configuré sur le réseau de développement (devnet) et non sur le réseau principal (mainnet) avant de continuer.

Pour frapper un NFT, vous devrez disposer de SOL devnet dans votre portefeuille Phantom. Vous pouvez utiliser la CLI Solana pour effectuer un airdrop vers votre portefeuille Phantom en saisissant cette commande dans votre terminal : 

Airdrop Solana 1 VOTRE_ADRESSE_DE_PORTEFEUILLE_PHANTOM

Lorsque vous êtes prêt, cliquez sur « Mint ». Si l'opération s'est déroulée correctement, vous devriez voir s'afficher une page web comme celle-ci :

Page « Bonbons à la menthe »

If you see an error that says “Mint Failed”, you might not have enough funds. Try again once you’ve added funds. You can view the NFT in your wallet after purchasing. Phantom may take a moment before rendering the NFT in your wallet. Ours looks like this:

NFT frappé dans le portefeuille

C'est vraiment un régal ! Bravo.

Conclusion

Congrats! You created a Candy Machine using Metaplex Sugar and have all the tools needed to run your own NFT mint. We're excited to see what NFTs you're creating! Join us on Discord or reach out to us via Twitter to share your NFT project. 

Nous ❤️ les commentaires !

Si vous avez des commentaires ou des questions concernant ce guide, n'hésitez pas à nous en faire part. Nous serions ravis d'avoir votre avis !

Partager ce guide