Search code examples
solanametaplex

How to connect two Candy Machines?


I need to create a collection with a total of 100 NFTs, where the first 10 (IDs 0 to 9) will be minted to the same wallet from the start, and the remaining 90 will have the possibility to be minted through a web page.

I understand that the procedure would be as follows:

  1. Create a CMv2 with a total of 10 assets.

  2. Mint all of them (because the minting is random, it must be done before adding the remaining NFTs).

  3. Create the second CMv2 with the remaining 90 assets. I must specify the address of the mint created in the first CMv2 (the "collection mint address") with the -m parameter.

However, I encounter several errors when doing this:

  • Case 1:

private.json -> "number": 10
public.json -> "number": 90

assets
├── private
│   ├── 0.json
│   ├── 0.png
│   ├── ...
│   ├── 9.json
│   └── 9.png
└── public
    ├── 10.json
    ├── 10.png
    ├── ...
    ├── 99.json
    └── 99.png
config
├── private.json
└── public.json
  • Case 2 (same file structure as above):

private.json -> "number": 10
public.json -> "number": 100

  • Case 3:

private.json -> "number": 10
public.json -> "number": 90

assets
├── private
│   ├── 0.json
│   ├── 0.png
│   ├── ...
│   ├── 9.json
│   └── 9.png
└── public
    ├── 0.json
    ├── 0.png
    ├── ...
    ├── 89.json
    └── 89.png
config
├── private.json
└── public.json
  • Case 4 (same file structure as above):

private.json -> "number": 10
public.json -> "number": 100

All 4 cases return the same error: Error Number: 6003. Error Message: Index greater than length!.


Solution

  • I had the same issue not to long ago take a look here: One Collection, Multiple Candy Machines

    First of all, I recommend using SUGAR CLI to upload & deploy the Candy Machines - the experience is smoother. If you are on Windows you can use WSL2. I also recommend getting a custom RPC, take a look at Quiknode - it's easy to setup.

    To upload and then deploy the public collection:

    sugar upload assets/public -c config/public.json --cache .cache/public.json -k <WALLET KEYPAIR.json> -l debug -r <RPC ENDPOINT URL>
    
    sugar deploy -c config/public.json --cache .cache/public.json -k <WALLET KEYPAIR.json> -l debug -r <RPC ENDPOINT URL>
    

    Repeat the same steps as above for the private collection (just change private wherever there is public).

    To set the same collection using SUGAR:

    sugar collection set --cache .cache/public.json -k <WALLET KEYPAIR.json> --candy-machine <CANDY MACHINE ID> --collection-mint <COLLECTION ADDRESS> -r <RPC ENDPOINT URL>
    

    Repeat for private assets.

    I've managed to show total number of NFTs on UI by connecting to the private machine and the public machine (you however cannot mint from the private machine using the UI) - this behavior is not supported by default, you are going to have to do some coding for that.

    And regarding the index problem, the different configurations should have done the trick (private.json & public.json) but if Metadata is the problem I used a python script to renumber the indexes properly - if that is something you are interested in I can provide.