# Candy Machine: Instructions The following steps are instructions on how to: 1. Download Node JS, Solana, and Metaplex's Candy Machine project 2. Create a treasury wallet 3. Upload to Arweave 4. Create and update a Candy Machine > [TOC] :::danger **IMPORTANT: These instructions and commands only work for Windows.** ::: --- ## Installations This section covers installing Node JS, Solana, and the Metaplex project from GitHub. ### 1. Node JS Download Node JS [here](https://nodejs.org/en/). ### 2. Solana Open your Command Prompt by searching "cmd" in the Windows search bar. Right click it and hit "Run as Administrator". Run `cd ..` twice to jump out of the current location. Then do: `cd Users` And then after hitting enter, run: `cd <DesktopName>` Now, copy and paste this in the terminal: `curl https://release.solana.com/v1.8.6/solana-install-init-x86_64-pc-windows-msvc.exe --output C:\solana-install-tmp\solana-install-init.exe --create-dirs` After that, run this: `C:\solana-install-tmp\solana-install-init.exe v1.8.6` And check that Solana is installed by running: `solana --version` Great! If all the commands ran successfully, Solana has been setup! ### 3. Metaplex Download the Metaplex project [here](https://github.com/metaplex-foundation/metaplex/releases/tag/v1.0.0), and extract the ZIP file. After you have finished installing Metaplex, go back inside the terminal and jump in the `metaplex` project folder. And then run these commands: `npm install -g ts-node` `npm install` `yarn` Now, go inside: `metaplex > js` And run: `yarn install` Next, jump into: `metaplex > js > packages > cli` And run: `yarn build` --- ## Solana Wallet Create a treasury wallet in the terminal and airdrop SOL tokens in it! ### 1. Creating the Wallet Run this in the terminal to create a wallet: `solana-keygen new --outfile C:/Users/<DesktopName>/.config/solana/<WalletName>.json` ### 2. Saving the Secret Phrase and Location After that is completed, save the output on a `.txt` file - for example, it may look like this: `Generating a new keypair` `For added security, enter a BIP39 passphrase` `NOTE! This passphrase improves security of the recovery seed phrase NOT the keypair file itself, which is stored as insecure plain text` `BIP39 Passphrase (empty for none):` `Wrote new keypair to C:/Users/<Username>/.config/solana/devnet.json` `=========================================================================` `pubkey: 6iFfxUthDeRcyD19xrPU6kjkNLojVGwrtMkymGrgMZ3G` `=========================================================================` `Save this seed phrase and your BIP39 passphrase to recover your new keypair: suit tie vest business coat scarf hat winter cold heat file paper` `=========================================================================` _**Note:**_ _This was a randomly generated seed phrase! Do not use it!_ ### 3. Set and Get Next, run this: `solana config set --keypair C:/Users/<DesktopName>/.config/solana/<WalletName>.json` If you wallet is successfully connected, you can check your wallet status with: `solana config get` ### 4. Airdropping SOL Tokens Now, to get a few SOL tokens to be able to upload your PNG + JSON pairs to Arweave using Metaplex, airdrop some SOL tokens into your wallet - but first, go on the `devnet`: `solana config set --url https://api.devnet.solana.com` And then run: `solana airdrop 1` :::info **Tip:** To switch to the `mainnet-beta`, run: `solana config set --url https://api.mainnet-beta.solana.com/` ::: --- If you've followed all the steps properly, you are on the `devnet`. A little advice, if you're on the `devnet` and want to test uploading your images, you should just pick 5 PNG + JSON pairs to test, rather then uploading all of your NFTs. After testing out your 5 PNG + JSON pairs, do this whole process again, but this time upload all your NFTs on the `devnet`, still. This is what we will do next! ***Note:** Following these instructions, from now on, run all these commands from your Metaplex project folder!* --- ## Arweave [Arweave](https://www.arweave.org/) is a storage program that allows you to store data permanently. We will use this to store our PNG + JSON pairs. ### 1. Uploading the PNG + JSON Pairs Now, we will upload our assets on the `devnet`. Open the Command Prompt again, and enter this: `ts-node C:/Users/<Username>/<Path to your candy-machine-cli.ts file> upload C:/Users/<Username>/<Path of your assets folder> --env devnet --keypair C:/Users/<Username>/<Path of your JSON wallet file>` Also, if you run into errors uploading to Arweave, also consider that your collection name might be too long, and you have that in your metadata. Example: `Name: "Hapy Air Balloon Day Celebration #1"` The max character limit for the collection name (in the metadata) is 32 characters. Keep in mind that you have to give space to the higher number as well - for example, you have 10,000 NFTs and your collection name is thirty four characters. Add the number 10,000 to your NFT name and calculate the amount of characters. **Bad Metadata** `Name: "Eggplants Forever Holiday Lake #10000"` **Good Metadata** `Name: "Eggplants Forever Lake #10000"` ### 2. Verifying Uploaded Assets Now, you can check your assets: `ts-node C:/Users/<Username>/<Path to your candy-machine-cli.ts file> verify -e devnet -k <C:/Users/<Username>/<Path of your JSON wallet file>` If this step throws an error, some of your assets may not be uploaded. You should try the upload step again. --- ## Candy Machine After we have finished uploading to Arweave, now we create a Candy Machine. ### 1. Creating the Candy Machine Once again, in the Command Prompt, run this: `ts-node C:/Users/<Username>/<Path to your candy-machine-cli.ts file> create_candy_machine -e devnet -k <C:/Users/<Username>/<Path of your JSON wallet file>` You can get the Candy Machine ID with this command: `ts-node C:/Users/<Username>/<Path to your candy-machine-cli.ts file> show -k <C:/Users/<Username>/<Path of your JSON wallet file> -e devnet` ### 2. Setting the Date and Price `ts-node C:/Users/<Username>/<Path to your candy-machine-cli.ts file> update_candy_machine -e devnet -k <C:/Users/<Username>/<Path of your JSON wallet file> --date <Date> --price <Price>` ***Note:** The date should look like this "05 Dec 2021 15:30:00 GMT" following the 24 hour time. Also, no other timezone works except for GMT. The price should be defined like this: 0.5* --- ## mainnet-beta A few more things you need to know for `mainnet-beta` - we will cover this in this section. ### 1. Custom RPC **What is it?** Remote procedure call. It is used to interact with Solana. **Why use one?** Speed and being able to mint without issues. You will be rate limited if you use the ones from Solana. When you upload all of your NFTs, say the total is 5,000, you will likely get a 429 error. It looks like this: `Server responded with 429 Too Many Requests.` The `devnet` MB limit is 10 MB. For the `mainnet-beta`, the limit is 250 MB. If you're getting rate limited on the `devnet` while uploading all your NFTs, that's okay, as the limit on the `mainnet-beta` is larger and your PNG + JSON size (if it's under 5,000) would probably be lower then that. However, it is suggested that you use a custom RPC. Why? Because you'll almost definitely get rate limited and have issues uploading, and later on minting. The most popular RPC among Solana developers is [Quicknode](https://www.quicknode.com/?tap_a=67226-09396e&tap_s=2286372-341e1b&utm_source=affiliate&utm_campaign=generic&utm_content=affiliate_landing_page&utm_medium=generic). If you choose to use Quicknode, then, when uploading to Arweave (or creating a Candy Machine, but we'll use this as an example), you should put `-r quick-node-url` at the end of the command. It'll look like this: `ts-node C:/Users/<Username>/<Path to your candy-machine-cli.ts file> upload C:/Users/<Username>/<Path of your assets folder> --env mainnet-beta --keypair C:/Users/<Username>/<Path of your JSON wallet file> -r quick-node-url` Also, there is a free RPC called GenesysGo that has no rate limit as they paid large amounts for it. It's free for now, but next year, it will no longer be free. Here are the RPC URLs: 1. [mainnet-beta](https://ssc-dao.genesysgo.net/) 2. [devnet](https://psytrbhymqlkfrhudd.dev.genesysgo.net:8899/) If you're uploading a lot of files, such as 2K+ then you would want to run the RPC command on both the upload and verify commands. You do not run the RPC command on creating a Candy Machine or updating it, only for uploading and / or verifying. ### 2. Tweaking the Commands Congratulations, you have successfully uploaded your assets to Arweave, and created and updated a Candy Machine on the `devnet`! Now you have to do this whole process again, but on the `mainnet-beta`. The command will change a bit, so for example, in uploading to Arweave on the `mainnet-beta`, instead of: `ts-node C:/Users/<Username>/<Path to your candy-machine-cli.ts file> upload C:/Users/<Username>/<Path of your assets folder> --env devnet --keypair C:/Users/<Username>/<Path of your JSON wallet file>` It will be: `ts-node C:/Users/<Username>/<Path to your candy-machine-cli.ts file> upload C:/Users/<Username>/<Path of your assets folder> --env mainnet-beta --keypair C:/Users/<Username>/<Path of your JSON wallet file>` --- ## Costs You might think that the high costs come from Arweave - actually, no. Most of the costs come from Candy Machine, but don't worry! In the next section, I'll explain how you can withdraw your SOL from the Candy Machine, once all your NFTs are minted. ### 1. Fee Calculators Good fee calculators: 1. [Arweave Fee Calculator](https://55mcex7dtd5xf4c627v6hadwoq6lgw6jr4oeacqd5k2mazhunejq.arweave.net/71giX-OY-3LwXtfr44B2dDyzW8mPHEAKA-q0wGT0aRM) 2. [Candy Machine Fee Calc](https://feecalc.live/) ### 2. Renting Candy Machine When you pay for Candy Machine, your NFTs will only stay there for two years - so there is no "buy" forever option, only rent. You can, however, change how long you can rent so you can pay less. However, if you can afford the two years of rent, it is suggested to pay for them and then use the withdraw command to retrieve the remaining Solana once the minting is done. If you decide to change the rent, the withdraw command might have some issues. (There is probably a 65% percent chance that it will give you a bunch of errors - that's my experience with Candy Machine 😅) This is the command to withdraw your SOL from Candy Machine: `ts-node C:/Users/<Username>/<Path of your candy-machine-cli.ts file> withdraw -e devnet -k C:/Users/<Username>/<Path of your JSON wallet file>` ***Note:** If you use the withdraw command, remember that you can't use the same Candy Machine anymore.* --- ## Common Errors | Error | Explanation | | -------- | -------- | | ENETUNREACH | If you see this, check or change your internet connection. Even if it is working to browse the web, this error can be fixed by changing internet connection. | | Metaplex Candy Machine Loop Error | If you have this error while uploading your assets, here are things you should try to fix it. First check your json files. Verify them with somenoe else if necessary. Second, check the path of your assets and verify that it is completely correct. | | Unexpected token or end of JSON input | Check your JSON file with the cli: `verify_token_metadata` | | 429 | You are being rate limited. You need a custom RPC. | | 0x139 | Not enough Solana. Fund your wallet. | | The term ‘git’ is not recognized as the name of a cmdlet: | Install `git` [here](https://git-scm.com/downloads). | | Invalid subscription ID | Verify after the upload is done. This shouldn’t give you an issue. | | SendTransactionError | Failed to send transaction: Node is behind by xxx slots: If you’re using a custom RPC, contact the provider otherwise try uploading again. | | TypeError | Cannot read properties of undefined (reading ‘digest’)…: Here is a possible solution. In your case you’ll probably have to use https. | --- ## FAQ | Question | Answer | | -------- | -------- | | Is there are way to make the upload cheaper? | Yes. To begin with, we no longer need to use an external program to upload our files to Arweave since upload costs is no longer fixed. To reduce cost, you can reduce the rent of the candy machinem, but keep in mind that it is recommened to leave the rent time as the default. | | What are the file size limits? | The minimum is 25KB, and the max is 9MB for the `devnet` and 250MB for the `mainnet-beta`. | | Can I upload more files to the same Candy Machine? | No. This is the reason why you need 2 candy machines to do presale. | | Can I do a reveal? | You can update your metadata with [Metaboss](https://hackmd.io/@archaeopteryx/By4bpbA4F). | | What are the differences between “family” and “name” under the collection section in the metadata? | The family is the broader term that ecompasses multiple collections, whereas the name identifies the current collection. | | Can you add more NFTs to a candy machine? | No. Once created, you cannot add more. | --- ## Shortcuts `-k` = Keypair (JSON wallet file) `-d` = Date `-p` = Price `-e` = Env --- ## Resources 1. [How to Create an NFT Minting Website UPDATED (Windows, Mac, Linux)](https://www.youtube.com/watch?v=4LLx7SMAOag) 2. [Solana NFTs: Everything you need](https://hackmd.io/@hnbl/hector)