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)

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.ini
    cp config.ini.example config.ini
  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.ini and change REPLACEME to your pubkey, save and close the file
    vim config.ini
  7. Initialize project
    python3 nftgen.py --project example --config config.ini --initialize
  8. Generate metadata
    python3 nftgen.py --project example --config config.ini --generate-metadata
  9. Generate assets, which moves the images and metadata into one folder
    python3 nftgen.py --project example --config config.ini --generate-assets
  10. Confirm you have the correct assets:
    ls projects/example/assets/
    • It will look like: 0.json 0.png 1.json 1.png
  11. 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. 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: