Skip to content

Instantly share code, notes, and snippets.

@christophersanborn
Created October 3, 2022 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christophersanborn/01e71e54d1e10c552beca5c9cfdc809f to your computer and use it in GitHub Desktop.
Save christophersanborn/01e71e54d1e10c552beca5c9cfdc809f to your computer and use it in GitHub Desktop.
Peerplays NFT deploy script
#!/bin/bash
##
## Note: You'll run this script several times to get various pieces of
## information along the way.
##
## It will create files under ./blobs/, but will not otherwise have
## side-effects.
##
##
## Step 1: NFT Storage:
##
## Upload folder of images to an IPFS pinning service, then retrieve the hash
## of the folder. Be sure to use the url-friendly hash format (should start
## with "bafybei")
##
## Example end result at:
## https://ipfs.artcasa.gallery/ipfs/bafybeidbpxnhns73t2le244n3l73q4ex6o4edu32bqgp72toarr6a6ukim
##
IMAGEFOLDERHASH=bafybeidbpxnhns73t2le244n3l73q4ex6o4edu32bqgp72toarr6a6ukim
##
## Step 2: Contract Setup: Configure your contract here.
##
## Name rules: (applies to SYMBOL as well as NAME)
##
## o Length: Must be between 3 and 15 chars
## o First char must be: [A-Za-z]
## o Subsequent chars: [A-Za-z0-9 ]
##
SYMBOL="MINTBEARSZERO"
NAME="Mint Bears Zero"
ISSUER="jaribu-kuivunja" # Will also be revenue partner and initial owner of minted NFTs
REVPCT=250 # Units of 0.01%. (I.e. 250 is 2.5%)
MAXSUPPLY=1000 # Max number of NFTs this contract can mint.
##
## Step 3: NFT Template
##
## Define a template for the descriptive data attached to each NFT.
##
## To understand the variable substitutions, see make_a_blob() function
## below.
##
## After defining template, JUMP TO END OF FILE for Step 4: Traits.
##
TEMPLATE='{"name":"Mint Bears #$1","created_by":"Masha","description":"Furry and fun MintBears! This is an early preliminary issuance of the Mint Bears. More to come?","image":"ipfs://$4","attributes":[{"trait_type":"Fur Color","value":"$2"},{"trait_type":"Eye Color","value":"$3"}]}'
##
## Step 5: Contract descriptive data
##
## NOTE: I SKIPPED STEP 4!!! (It's at the END of the file. Go there first.)
##
## Template for descriptive data of entire collection:
##
## BASEHASH: An optional URL for ALL of your NFT data.
##
## If you want this to include the JSON blobs for every NFT in your set,
## you'll need to generate these and upload to IPFS first, and THEN get this
## hash. (This script will generate the blob files you need under ./blobs/)
##
## MDID: You'll get this AFTER you create the metadata object. It will be
## used to mint individual NFTs. OK if you don't know it yet.
##
BASEHASH=bafybeicym3epgdalnw6r3gns57njic57e34i4zn5jhg655zubdrwgxxise
MDID="1.30.8"
MDTEMPLATE='{"name":"Mint Bears Zeroth Run","created_by":"Masha","description":"Furry and fun MintBears! This is an early preliminary issuance of the Mint Bears. More to come?","base_uri":"ipfs://'"$BASEHASH"'"}'
##
## SKIP AHEAD:
##
## Script does stuff here. You can skip to "Step 4: Traits" below.
##
MDTEMPLATE=$(echo "$MDTEMPLATE" | sed 's/\"/\\\"/g')
TEMPLATE=$(echo "$TEMPLATE" | sed 's/\"/\\\"/g')
mkdir -p blobs
echo "###"
echo "### METADATA CREATE: Issue this command in cli_wallet to deploy contract."
echo "### (Be sure you've uploaded blobs and determined BASEHASH already.)"
echo "### Change final arg from 'false' to 'true' to broadcast. (Else it's dry-run.)"
echo "###"
echo
# nft_metadata_create owner_account_id_or_name name symbol base_uri optional<revenue_partner> optional<revenue_split> is_transferable is_sellable, optional<role_id> optional<max_supply> optional<lottery_options> broadcast
echo "nft_metadata_create $ISSUER \"$NAME\" \"$SYMBOL\" \"$MDTEMPLATE\" $ISSUER $REVPCT true true null $MAXSUPPLY null false"
echo
echo
echo "###"
echo "### NFT CREATE: Issue these commands in cli_wallet to mint each NFT."
echo "###"
echo
make_a_blob() { # $1:idx $2:tval1 $3:tval2 $4:hash $5:outfile
#
# Constructs a descriptive NFT blob and (1) writes it to a file so you can
# upload to IPFS, and (2) composes a cli_wallet command you can use to mint
# this NFT.
#
blob=$(eval echo \""$TEMPLATE"\")
echo -n "$blob" > $5
blob=$(echo "$blob" | sed 's/\"/\\\"/g')
echo $SYMBOL:$1
echo
echo nft_create $ISSUER $MDID $ISSUER $ISSUER \""$blob"\" false
echo
}
##
## Step 4: Traits
##
## Declare the Trait Values of your NFTs here. This part also produces the
## metadata blobs that you need (optionally) to upload to get your contract
## BASEHASH, and it suggests the cli_wallet commands necessary to mint the
## NFTs.
##
make_a_blob 0 Brown Blue $IMAGEFOLDERHASH/0.png blobs/0.json
make_a_blob 1 Brown Red $IMAGEFOLDERHASH/1.png blobs/1.json
make_a_blob 2 Green Blue $IMAGEFOLDERHASH/2.png blobs/2.json
make_a_blob 3 Green Red $IMAGEFOLDERHASH/3.png blobs/3.json
echo "###"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment