Last active
December 13, 2021 13:41
-
-
Save kwrooijen/ea459e66f0d2eef81deb121f7739ddec to your computer and use it in GitHub Desktop.
A script for creating NFTs on the Elrond Network
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Deriving PEM file | |
# | |
erdpy --verbose wallet derive wallet.pem --mnemonic | |
# Elrond Network Variables | |
CONTRACT_ADDRESS="erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" | |
PROXY="https://devnet-gateway.elrond.com" | |
CHAIN="D" | |
# User Variables | |
OWNER_ADDRESS="erd1fhwm9gruam74lmaxmuqchrz5kd43qnjznk4z8lzw34f34g6dl99snwxd5u" | |
PEM="wallet.pem" | |
NAME="awaitnil" | |
TICKER="AWT" | |
ID="AWT-302d62" | |
# Utility Functions | |
hex() { printf "0x%s" $(echo -n $@ | xxd -p -c 10000000000000000); } | |
egld() { printf "%.0f" $(bc <<< 10^18*$1); } | |
royalties() { printf "%.0f" $(bc <<< 100*$1); } | |
decode_bech32() { printf "0x%s" $(erdpy wallet bech32 --decode $1); } | |
hash_img() { cut -b-64 <<< $(sha256sum $1); } | |
# Contract Functions | |
issue_nft() { | |
# Arguments: | |
# $1 : issueNonFungible | |
# | issueSemiFungible | |
# $2 : Token Name | |
# $3 : Token Ticker | |
erdpy contract call $CONTRACT_ADDRESS \ | |
--pem $PEM \ | |
--chain $CHAIN \ | |
--proxy $PROXY \ | |
--function $1 \ | |
--arguments $(hex $2) $(hex $3) \ | |
--value $(egld 0.05) \ | |
--gas-limit 60000000 \ | |
--recall-nonce \ | |
--send | |
} | |
set_special_role() { | |
# Arguments: | |
# $1 : Token Identifier | |
# $2 : Owner address | |
# $3~ : | ESDTRoleNFTCreate | |
# | ESDTRoleNFTBurn | |
# | ESDTRoleNFTAddQuantity (SFT only) | |
for role in ${@:3}; do ROLES="${ROLES} $(hex $role)"; done | |
erdpy contract call $CONTRACT_ADDRESS \ | |
--pem $PEM \ | |
--chain $CHAIN \ | |
--proxy $PROXY \ | |
--function setSpecialRole \ | |
--arguments $(hex $1) $(decode_bech32 $2) $ROLES \ | |
--gas-limit 60000000 \ | |
--recall-nonce \ | |
--send | |
} | |
esdtnft_create() { | |
# Arguments: | |
# $1 : Token Identifier | |
# $2 : Quantity | |
# $3 : NFT Name | |
# $4 : Royalties | |
# $5 : Hash | |
# $6 : Attributes | |
# $7~ : URI | |
for uri in ${@:7}; do URIS="${URIS} $(hex $uri)"; done | |
erdpy contract call $OWNER_ADDRESS \ | |
--pem $PEM \ | |
--chain $CHAIN \ | |
--proxy $PROXY \ | |
--function ESDTNFTCreate \ | |
--arguments $(hex $1) $2 $(hex $3) \ | |
$(royalties $4) $(hex $5) \ | |
$(hex $6) $URIS \ | |
--gas-limit 70000000 \ | |
--recall-nonce \ | |
--send | |
} | |
# Issue a new | |
# | |
# https://docs.elrond.com/developers/nft-tokens/#issuance-of-non-fungible-tokens | |
# https://docs.elrond.com/developers/nft-tokens/#issuance-of-semi-fungible-tokens | |
issue_nft issueNonFungible $NAME $TICKER | |
# Set special roles | |
# | |
# https://docs.elrond.com/developers/nft-tokens/#assigning-roles | |
set_special_role $ID $OWNER_ADDRESS ESDTRoleNFTCreate ESDTRoleNFTBurn | |
# Create an NFT | |
# | |
# https://docs.elrond.com/developers/nft-tokens/#creation-of-an-nft | |
QUANTITY=1 | |
NAME="Awaitnil #1" | |
ROYALTIES=20 | |
HASH=$(hash_img "nft.png") | |
ATTRIBUTES="user:awaitnil;eyes:lightning" | |
URI="https://ipfs.io/ipfs/QmVG5Ah1zCjNtirxC89jQLzTnqHDMrmcVvFNAzKghAnBpq" | |
esdtnft_create $ID $QUANTITY "${NAME}" $ROYALTIES $HASH "${ATTRIBUTES}" $URI |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment