# Candy Machine v2 - Notes from the office hours V2? V2! There are different reasons for a new Version. The one that triggered our man Jordan was probably bots sniping on mints. :::success Follow me on Twitter :bird:[@MarkSackerberg](https://twitter.com/MarkSackerberg) if you like my work. You can also DM me or :bird:[@9HOMIES](https://twitter.com/ninehomies) if you want to work together! ::: :::info Have a look at :bird:[SolSlimes](https://twitter.com/SolSlimesNFT) to see more of my work! ::: ## Key differences There are quite big changes and I will elaborate on them in the future, but first have some top level bullet points to get an overview: * Whitelist * With SPL Tokens (airdropped or distributed via gumdrop) * presale boolean allows users with the token to mint before the start date * Payment with presale token + SOL possible * discounted price for users with tokens possible * Whitelist token can either be burned or stay with the holder * Randomized mint * Bots will not be able to mint specific NFTs anymore because the next mint is determined quite randomly. Not just based on a counter anymore * Gatekeeper / Captcha * Some kind of captcha integration (currently with Civic Technologies). Result is stored on chain, so if you activate that the UX might not be as good as before but no bots can mint! * In the futre other Gatekeepers than civic are possible. * All settings modifiable. * With v1 you could e.g. not change the "currency". Now you can change the accepted mint * ExiledApes mint button not compatible anymore. You can use the candy machine ui or community frontends instead ## Build your own! From my point of view the things got much easier. At least less commands are required. But let's do it step by step: Clone & install Metaplex 1. `git clone https://github.com/metaplex-foundation/metaplex.git` Clone metaplex from github. If you already have metaplex locally make sure to run `git pull` . 2. go into js folder (`cd js`) 3. run `yarn install` ### 1. Settings One huge difference to v1: The candy machine and config are one account now. Therefore we need to provide all the information directly (can be updated though). We don't have a create_candy_machine command later on. We do not do the configuration with hundreds of CLI parameters anymore. Instead we can build a config.json file for most of our parameters. The [documentation](https://github.com/metaplex-foundation/metaplex/blob/master/js/packages/cli/README.md#settings-examples) on this is already quite good, so I will skip explaining all the parameters for now. Make sure that you do not delete anything but instead set them to `null`. E.g. if you don't need the endSettings do '"endSettings": null' instead of removing the line completely. Otherwise you will receive error 0x66 Use this as basis and save it somewhere e.g. as config.json ``` { "price": 0.01, "number": 6, "gatekeeper": null, "solTreasuryAccount": "G2j7mmWuA9AH7u8Ykxm1hSuizxJk8u8YYBUZkuMvmytM", "splTokenAccount": null, "splToken": null, "goLiveDate": "11 Dec 2021 13:00:00 GMT", "endSettings": { "endSettingType": { "amount": true }, "value": 5 }, "whitelistMintSettings": { "mode": { "burnEveryTime": true }, "mint": "7nE1GmnMmDKiycFkpHF7mKtxt356FQzVonZqBWsTWZNf", "presale": true, "discountPrice": 0.5 }, "hiddenSettings": null, "storage": "arweave", "ipfsInfuraProjectId": null, "ipfsInfuraSecret": null, "awsS3Bucket": null, "noRetainAuthority": false, "noMutable": false } ``` Explanation for the different fields in config.json | Option | Sub-Option | possible values | description | | -------- | -------- | -------- | ---- | | Price | | Numbers | Price in SOL or SPL tokens| | number | | Integer |Amount of NFTs in the candy machine| | solTreasuryAccount||Publickey / null| Account SOL proceedings should go to |splTokenAccount||Publickey / null|Account SPL proceedings should go to |splToken||Publickey / null|Mint Adress of the SPL token the machine is paid with |goLiveDate||Datetime|Date where "normal" users can mint. (Can be circumvented by CM Authority and whitelist) |endSettings||options / null |Date or mint amount after which the Candy machine is closed ||endSettingstype||type of end setting ||-amount|boolean|end after n mints| ||-value |Integer|amount of mints before end tbc... ### 2. Upload This step is similar to v1. Except that we need to add one config parameter `-cp <config location>` e.g. your command could look like this: ``` ts-node candy-machine-v2-cli.ts upload -e devnet -k <path to keyfile> -cp <path to config.json> <path to assets> -c <cache file name> ``` ### 3. Verify :::danger DO NOT SKIP THIS STEP! ::: This step checks if the upload of all files was successful. Command can look like that: ``` ts-node candy-machine-v2-cli.ts verify -e devnet -k <path to keyfile> -cp <path to config.json> -c <cache file name> ``` Only proceed if it says successful. Otherwise run the upload command again! ### 4. Mint That's it already. You can test your candy machine with the mint_one_token command. ``` ts-node candy-machine-v2-cli.ts mint_one_token -e devnet -k <path to keyfile> -cp <path to config.json> -c <cache file name> ``` ### 5. Build a frontend Well, I lied. The candy machine is set up and technically you can mint, but obviously you want to give your community the chance to mint, too. Unfortunately the v1 standard "exiledApes" mint button repository does not work anymore. But there are alternatives. #### candy machine ui You can use the frontend of the fair launch protocol which is already in the metaplex repository. Just go into `metaplex/js/packages/candy-machine-ui` and modify the `.env` file. 1. After REACT_APP_CANDY_MACHINE_ID add the ID of your candy machine. The ID was printed when running the upload command. You can also see it in the file in the .cache folder in `metaplex/js/packages/cli/src/.cache` 2. Change to correct network. I was talking about devnet the whole time, so make sure that no `#` is in front of the lines with devnet (line 3+4) but instead in front of mainnet (line 6+7) like you can see below ``` REACT_APP_CANDY_MACHINE_ID=<YOUR CANDY MACHINE PROGRAM ID> REACT_APP_SOLANA_NETWORK=devnet REACT_APP_SOLANA_RPC_HOST=https://api.devnet.solana.com ``` 3. Run `yarn start` in `metaplex/js/packages/candy-machine-ui` to run a local version of the front end. You can test minting here! 4. Do changes to the frontend. It's lame if all look the same! 5. Deploy it to cloudflare / vercel / whatever. #### Community frontend by TonyBoyle.eth https://github.com/tonyboylehub/candymachine-v2-boiler-mint-site-noFLP # Caveats ## 1. Gumdrop Currently Gumdrop will not directly work with v2 right now. [Jordan confirmed](https://twitter.com/redacted_j/status/1471285790508523520) that it will work in the future, though. There is a workaround: 1. Use gumdrop to give your users SPL tokens 2. Modify the candy machine config to accept the SPL token as whitelist token. # FAQ & Troubleshooting ## Using SPL tokens as whitelist token 1. create a SPL token. Make sure to use option `--decimals 0` e.g. like `spl-token create-token --decimals 0` 2. Distribute it to your users. (e.g. with [Gumdrop](/6yf_s3p9T0OIUIgH3j_XRQ)). (can also be done ofter setting up the machine) 3. Configure your candy machine. The following config will accept a presale token and burn 1 on every mint. It will not give a discounted price. One examle config file that has been confirmed working. Look into the [docs](https://github.com/metaplex-foundation/metaplex/blob/master/js/packages/cli/README.md#whitelist-mint-settings) for more details! ``` "price": 0.01, "number": 10, "gatekeeper": null, "solTreasuryAccount": "<your wallet>", "splTokenAccount": null, "splToken": null, "goLiveDate": "1st Jan 2022 00:00:00 GMT", "endSettings": { "endSettingType": { "date":true }, "value":"25 Dec 2022 23:59:00 GMT" }, "whitelistMintSettings": { // THIS IS THE IMPORTANT THING HERE! "mode" : { "burnEveryTime": true }, "mint" : "E5BuTQcD22n6FyC2RWMtVNH2uZVNqAcy5855P8GrTxx4", //your SPL token mint "presale" : true, //enable the wallets having the token to mint before start date "discountPrice" : null // preminter have same price as normal minters }, "hiddenSettings": null, "storage": "arweave", "ipfsInfuraProjectId": null, "ipfsInfuraSecret": null, "awsS3Bucket": null, "noRetainAuthority": false, "noMutable": false } ``` ## TypeError: Cannot read properties of undefined (reading 'slice') / FLP Frontend not working Thats an [issue](https://github.com/metaplex-foundation/metaplex/issues/1306) with the current master branch. FLP frontend is broken here. You can e.g. use the branch `fix-arweave-upload` Clone it with `git clone -b fix-arweave-upload https://github.com/metaplex-foundation/metaplex.git` or just copy the flp folder out of this branch. Some Reports say that it helps to 1. checkout the above branch, 2. copy the `/js/packages/fair-launch` folder to another location 3. run `yarn add -d @types/canvas-confetti` if that does not work try `npm i --save-dev @types/canvas-confetti` 4. run `yarn install` and `yarn start` ## Signing your NFTs The sign_all CLI command does currently not work for candy machine v2. It does not find unverified metadata. What you can do is use [Metaboss](https://metaboss.rs/) to sign your NFTs. Donwload it and run `metaboss sign all -k <path-to-keypair> --candy-machine-id <first-creator-pubkey>` Make sure that you are NOT using the candy machine ID but the first creator instead. ## Error: The file assets/.DS_Store is not a supported file type There is a hidden Folder called .DS_Store in your asset folder. In case you can't find it you can run this script to delete it. `find ./assets -name .DS_Store -exec rm {} ;`