Tezos NFT creation for beginners


Today we will be creating a very simple NFT using the Tezos NFT standard created by Stove Labs with support from the Tezos Foundation. The entire smart contract is well under 100 lines of code, and it makes use of Ligo Lang, a friendly smart contract language for Tezos.

1) Install Ligo Lang

Follow the tutorial:
https://ligolang.org/docs/intro/installation/#dockerized-installation-recommended

You will need docker as a dependency.

2) Download the NFT standard smart contract
https://github.com/stove-labs/nft.stove-labs.com/blob/master/src/contracts/nft.ligo

Optionally set your text editor syntax to Pascal for improved visibility, but note that it will not work perfectly.

Important: replace all instances of "fail(" to "failwith(". The Ligo lang format has changed since the contract was developed.

3) Set your custom NFT metadata parameters
From line 3 to 6 you will see that there is a data type called a record where metadata for the NFT is stored.
// @remarks Meta data will be added to this record.
type nft is record [
    owner : address;
] 

You can add parameters using any of the Ligo Lang built in data types.

We will add some example parameters to make an NFT for a cat:
// @remarks Meta data will be added to this record.
type nft is record [
    owner : address;
] 
type nftMetaData is record [
  nftId : nftId;
  catName : string;
  catColor : string;
]

4) Compile & deploy the Contract

Below is the code to compile and deploy your contract
# Compile the LIGO contract
$ ligo compile-contract nft.ligo main > nft.tz

# Originate the compiled contract using the tezos-client
$ tezos-client originate contract nft for alice transferring 0 from alice running nft.tz --init '"{ Elt 1 \"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx\" }"

5) Mint your NFTs

The mint function accepts the second parameter nftToMint. You will compile the metadata in here for the custom parameters you defined earlier.
# Compile the LIGO transaction parameter into it's Michelson representation
$ ligo compile-parameter nft.ligo main 'Mint(record nftToMintId = 2n ; nftToMint = record owner = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address); end; end)'
(Left (Right (Pair "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" 2)))

# Invoke the contract by a parametrized transaction
$ tezos-client transfer 0 from alice to nft --arg '(Left (Right (Pair \"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx\" 2)))'

That's all, your NFT is now live. To interact with your NFT and build a dapp connecting to it, you can use the Typescript SDK by Stove Labs, which can be installed with:

npm i @stove-labs/tezos-nft-sdk

The reference for the SDK is available here.

Let us know what NFTs you make on Tezos! You can view Source Code on Github. Tag us on twitter or instagram @tezospage for a shout out.