Solana

Zero-to-Solana First Metaplex

Going from Zero to Solana; running your first metaplex upload with no pre-requisites

A. Introduction

No pre-requisites required. You do not have to have read the first post in the series to run this, because we’ll put the setup steps in this document.

Goal for this is to be copy-paste in-order from a fresh system mint an NFT using metaplex on Solana devnet, all on a single page with numbered steps (so you can get help debugging)

An overview of the entire workflow is:

  1. Create an environment, Ubuntu 20.04
  2. Install solana and metaplex binaries
  3. Use an NFT generator to create metadata and jpegs
  4. upload metadata and jpegs to storage (arweave in this guide)
  5. Create CANDY MACHINE with the metadata you generated
    • At this point, the admin can mint
  6. Set start time for candy machine to allow users to start minting
    • At this point, users may mint
  7. If you have a UI, users may then click “mint” and they get the token

B. Set up a VM using Multipass

The only way to get away with the OS-agnostic approach is to run everything on a a Ubuntu 20.04 and access via SSH command-line and tunneling.

We’ll use multipass, as this is cross-platform. Feel free to use VirtualBox, Parallels, or a cloud VM from AWS to load up the Ubuntu system.

On your host system open up a terminal (or Powershell):

After installation, in your terminal, run:

multipass launch -n zerotosolana -m 8G -d 100G
  • This will create an Ubuntu 20.04 VM named zerotosolana with 8GB of ram and 100GB of (virtual) disk space. Feel free to change these

Get into your shell like so:

multipass shell zerotosolana
  • Note: This uses the autogenerated SSH keys in your multipass setup. You may override these and simply use ssh with a cloud-init.yaml file, which is out of scope for this doc

Install npm and yarn

We will upgrade the system node to install yarn, and then we will install nvm which lets us switch node versions for different projects

C1. Install system npm and yarn in Ubuntu VM

  1. Update apt database
    sudo apt update
  2. Add apt source list
    curl -sL https://deb.nodesource.com/setup_14.x | sudo bash -
  3. Install nodejs and npm
    sudo apt -y install nodejs npm
  4. Install yarn
    sudo npm install --global yarn

C2. Install nvm to manage node versions

  1. Install nvm
    sudo apt install -y curl 
    curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
  2. Source profile
    source ~/.profile   
  3. install specific version of node with nvm
    nvm install 14.17.6
  4. use specific version of node with nvm
    nvm use 14.17.6
  5. Confirm you are using:
    node -v
    • It should say something like v14.17.6

D. Install metaplex

  1. Clone metaplex
    git clone https://github.com/metaplex-foundation/metaplex.git gh_metaplex-foundation_metaplex
  2. Get into the cli directory
    cd gh_metaplex-foundation_metaplex/js/packages/cli
  3. (optional) if you want to use the same version as this guide:
    git checkout fda50663d76c93295e05962926c4c17f400397d8 # 2021 Sep 15 has the --no-bytecode fix
    • metaplex is going through massive daily updates, so recommend you use the same version
  4. Build and install using the linux bytecode fix:
    yarn install
    yarn build
    yarn run package:linuxb
  5. Add path to profile
    echo export PATH=\"$(pwd)/bin/linux/:\$PATH\" >> ~/.profile
  6. Source to get metaplex
    source ~/.profile
  7. Check metaplex to see if it works:
    metaplex --version
    • It should look something like this:
    > metaplex --version
    0.0.1

E. Solana

Note: we will use devnet and keygen switches explicitly. You may create a config file later to override mainnet defaults.

  1. Install solana, around 240MB
    sh -c "$(curl -sSfL https://release.solana.com/v1.7.11/install)"
    • It will update the PATH in your .profile file to this:
      export PATH="/home/ubuntu/.local/share/solana/install/active_release/bin:$PATH"
  2. Get access to solana
    source ~/.profile
  3. Confirm access to solana binary:
    solana --version
    • You will see solana-cli 1.7.11 (src:bdb77b0c; feat:1140394761)
  4. Generate keypair
    solana-keygen new --outfile ~/.config/solana/devnet-lightcycle.json
    • It will look something like:
    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 /home/ubuntu/.config/solana/devnet-lightcycle.json
    ==========================================================================
    pubkey: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    ==========================================================================
    Save this seed phrase and your BIP39 passphrase to recover your new keypair:
    fake seed lightcycle research is the best fake seed fake seed fake seed
    ==========================================================================
  5. Request 10 SOL airdrop on devnet
    solana --url devnet --keypair ~/.config/solana/devnet-lightcycle.json airdrop 10
  6. Confirm balance
    solana --url devnet --keypair ~/.config/solana/devnet-lightcycle.json balance

F. Generate Assets

We will make two example NFTs for uploading

  1. Install python3
    sudo apt install -y python3
  2. Clone the lightcycle nft generator project:
    git clone https://github.com/lightcycleresearch/lightcycle-nft-generator.git gh_lightcycleresearch_lightcycle-nft-generator
  3. Change into directory
    cd gh_lightcycleresearch_lightcycle-nft-generator
  4. Create config.yaml
    cp config.yaml.example config.yaml
  5. Get your solana pubkey and copy it to your clipboard for the next step:
    solana-keygen pubkey ~/.config/solana/devnet-lightcycle.json
  6. Edit config.yaml and change REPLACEME to your pubkey, save and close the file
    vim config.yaml
  7. Create venv
    python3 -m venv venv
  8. Activate venv
    source venv/bin/activate
  9. Install requirements
    pip install -r requirements.txt
  10. Initialize project
    python3 nftgen.py --project example --config config.yaml --initialize
  11. Generate metadata
    python3 nftgen.py --project example --config config.yaml --generate-metadata
  12. Generate images
    python3 nftgen.py --project example --config config.yaml --generate-images
  13. Generate assets, which moves the images and metadata into one folder
    python3 nftgen.py --project example --config config.yaml --combine-assets
  14. Confirm you have the correct assets:
    ls projects/example/assets/
    • It will look like: 0.json 0.png 1.json 1.png 2.json 2.png
  15. Get into the project directory to prepare for the next step
    cd projects/example

G. Metaplex

We will upload, verify, create a candy machine, and mint a token with metaplex. We must create the candy machine before minting

  1. Ensure you are in the correct directory with the assets folder:
    pwd
    • It should look something like: /home/ubuntu/gh_lightcycleresearch_lightcycle-nft-generator/projects/example
  2. Check you have the assets folder available:
    ls
    • It should look like: assets/ images/ metadata/
  3. Confirm you have the correct assets:
    ls projects/example/assets/
    • It will look like: 0.json 0.png 1.json 1.png
  4. Run metaplex upload:
    metaplex upload ./assets --env devnet --keypair ~/.config/solana/devnet-lightcycle.json
    • If it fails, run it again. Sometimes it takes a few tries
    • It will look something like:
      Processing file: 0
      ...
      ...
      Processing file: 1
      Started awaiting confirmation for xxx
      REST null result for xxx null
      Resolved via websocket { err: null }
      Returning status { err: null, slot: 81091320, confirmations: 0 }
      Latency xxx 1.9210000038146973
      transaction for arweave payment: {
      txid: 'xxx',
      slot: 81091320
      }
      File uploaded: https://arweave.net/xxx
      Writing indices  0 - 1
      Done
  5. Verify the upload:
    metaplex verify --env devnet --keypair ~/.config/solana/devnet-lightcycle.json
    • It will look something like:
      Looking at key  0
      Name lightcycle #0 with https://arweave.net/xxx checked out
      Looking at key  1
      Name lightcycle #1 with https://arweave.net/xxx checked out
  6. Create candy machine, so we can mint later:
    metaplex create_candy_machine --env devnet --keypair ~/.config/solana/devnet-lightcycle.json 
    • It will look something like:
      wallet public key: xxx
      create_candy_machine finished. candy machine pubkey: xxx
  7. Set a start date and price, so tokens can be minted on UI and CLI. I picked a start date in the past, you may change it
    metaplex update_candy_machine --env devnet --keypair ~/.config/solana/devnet-lightcycle.json --price 0.5 --date "01 Sep 2021 00:00:00 GMT"
    • It’ll look something like:
      wallet public key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
      - updated startDate timestamp: 1630454400 (01 Sep 2021 00:00:00 GMT)
      - updated price: 500000000 lamports (0.5 SOL)
      updated_candy_machine Done xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  8. Mint a token for testing
    metaplex mint_one_token --env devnet --keypair ~/.config/solana/devnet-lightcycle.json  
    • It will look something like:
    wallet public key: xxx  
    Done xxx

Resources and References

You may read more for details: