---
# System prepended metadata

title: Louis' how2 for metaplex and candy machine

---

# Louis' how2 for metaplex and candy machine


## Prerequisites
**Step 1: Install node and npm**
    https://nodejs.org/en/
    how to install node:
    https://phoenixnap.com/kb/install-node-js-npm-on-windows

**Step 2: Install yarn**

Once installed install yarn with the command.
>npm install --global yarn

**Step 3: Install and setup solana cli**

This is a command line tool to interact with the solana blockchain.
This can be done following: https://docs.solana.com/cli/install-solana-cli-tools

-Once installed create a new keypair using the following commands:

>solana-keygen new --outfile ~/config/solana/new_keypair.json 

This is the keypair to the paper wallet you will be using for developing.
It will output something like this.

pubkey: AV3S5wzpcVU7yryEZ5NHajkxuzbvNToCWE7HYZreqooo

Save this seed phrase and your BIP39 passphrase to recover your new keypair:
old reunion equip battle none sudden marble thunder ignore fiction predict faint

The pubkey and recovery phrase. KEEP THESE SAFE!!!

-Once created set the solana cli to use your generated keypair using:
>solana config set --keypair ~/config/solana/new_keypair.json 

-Now set the network that the project will build on, devnet, testnet and mainnet. Devnet and testnet are for testing and mainnet is for full deployment.

Main net
>solana config set --url https://api.mainnet-beta.solana.com

Devnet
>solana config set --url https://api.devnet.solana.com

-To validate your wallet you will need to add some SOL to your wallet, as all transactions cost SOL. If you're on the mainnet you will need to buy or get a pal to transfer you some SOL. On the devnet you can just use the command

>solana airdrop 5 

to add 5 sol, show your balance using

>solana balance

**Step 4: git for windows**

If you have windows install git for windows or use preferred method for cloning git repos 
https://gitforwindows.org/


## Installing and setting up Metaplex

**Step 5: clone git**

Use the git cmd for windows or bash for ubuntu/mac to clone the below git repo, this will download the metaplex into the current directory.
>git clone https://github.com/metaplex-foundation/metaplex

**Step 6: building and running metaplex**

Open the cloned metaplex folder with VS code or preferred IDE.
Open a new terminal and cd into the js folder into metaplex.


Build and install metaplex by running the following commands:
>yarn
yarn build
yarn install
yarn bootstrap

Metaplex is now installed hurray!!!!

## Generating images
**step 8:**
create folder an assets in the metepex folder, then move the generated files to the assets folder
Two things I learnt the hard way, the upload does not like too small png’s, over 500x500.
The name in the metadata can’t be longer than 32 chars, also found out the hard way.




## Uploading the assets to arweave
In this step the images and json files the nft's point to are uploaded to arweave.  This step takes the longest of all, for an upload of 6666 images it took about 24 hours, be prepared to leave your pc on for a while.
It also cost SOL, for the rent on arweave and for the transaction fees, the 6666 images in all cost about 14 SOL.
This is no issue on devnet as you can airdrop SOL, but should be taken into account if doing a full deployment.

**step 7: running upload command.**
In the command line go to the metaplex folder, ie cd .. back from the js folder, and run the command

>ts-node js/packages/cli/src/candy-machine-cli.ts upload ./assets --env mainnet-beta --keypair  ~/config/solana/new_keypair.json

Once that has finished run the following command to verify to upload

> ts-node js/packages/cli/src/candy-machine-cli.ts verify --env mainnet-beta --keypair ~/config/solana/new_keypair.json 

This will check if all the files were correctly uploaded and indexed.

When finished, run upload again, it will re-upload any files that failed.
> ts-node js/packages/cli/src/candy-machine-cli.ts upload ./assets --env mainnet-beta --keypair  ~/config/solana/new_keypair.json

Once this a file will devent-temp will have been created in .cache folder in metaplex. This has links to all the jsons and images stored on arweave.

That is the hard bit over and you can now relax!

## Creating candy machine
Next you will be creating a candy machine, this is a back smart contract where the people can connect and buy an NFT.
First the candy machine is created using the following command.
>ts-node js/packages/cli/src/candy-machine-cli.ts create_candy_machine --env mainnet-beta --keypair ~/config/solana/new_keypair.json  --price 5

This will output a config ID for candy machine and it will look like this
config for a candy machine with publickey: FGwQYuJLvh9GRDdjgB6pRSC1rFEYmRPB1pUfEDyu7qnp.
SAVE THIS KEY!!!

Next you want to update the candy machine with time and price (the price has been done before but incase you need to do it again)
Using:
> ts-node js/packages/cli/src/candy-machine-cli.ts update_candy_machine  --env mainnet-beta --keypair  ~/config/solana/new_keypair.json  --price 0.666 --date "28 Oct 2050 18:00:00 UTC"

The candy machine is now live, so its essential that a time in the future is set and I recommend putting a high initial price until launch. 

This will output the candy machine pubkey, also very important! SAVE IT.
It will also output a timestamp, this also needs to be saved.
the time stamp will look like this.
updated startDate timestamp: 1634602320

The saved information up to now should be your pubkey, candy machine config id, candy machine pubkey and time stamp.

## Re-Creating candy machine
If there is an error with creating the candy machine, fear not!!!, once the assets are uploaded to arweave you can recreate a candy machine. (I did not know this...pain)

To re-create a candy machine go to the devnet-temp file and edit the uuid number by 1 digit or two, it just has to be different. Once this is done go back through the create candy machine steps.



## deploying a candy machine
To deploy your candy machine use vercel: https://vercel.com/
Create an account and add the following clone the following repo.
https://github.com/exiled-apes/candy-machine-mint
Once deployed, go to settings, environment variables, and add the saved environment variables from before.

env variables for vercel:
REACT_APP_CANDY_MACHINE_CONFIG=found in cache file
REACT_APP_CANDY_MACHINE_ID=given after create candy machine
REACT_APP_TREASURY_ADDRESS=keypair address
REACT_APP_CANDY_START_DATE=time stamp
REACT_APP_SOLANA_NETWORK=devnet
REACT_APP_SOLANA_RPC_HOST=https://api.devnet.solana.com

Redeploy the vercel cite with the new environment variables and your ready to mint.

helpful resources:
Metaplex is very buggy, when not if there is an issue, most probably someone else has faced the same issue. Use the git repo issues page and there will most probably bee a solution.
https://github.com/metaplex-foundation/metaplex/issues

These videos take you through the whole process.
https://www.youtube.com/watch?v=4LLx7SMAOag&t=609s 

https://www.youtube.com/watch?v=0_-mP0RjsVI 


TIPS: D6Aie5MeHqm25M77nDaa3nvxQcwhEW19uqAgxmGX2sGh 
