Tezos: Create an NFT on the Tezos Network using IPFS on Filebase
This guide was originally published on https://docs.filebase.com. Check out the Filebase documentation site for the latest Web3 tutorials using IPFS through Filebase.
Learn how to create an NFT on Tezos with IPFS on Filebase.
What is Tezos?
Tezos is an open-source, decentralized blockchain network that serves as a platform for executing peer-to-peer transactions and deploying smart contracts.
This tutorial uses a pre-compiled FA2 NFT contract that uses a command line interface to originate and interact with the NFT contracts. FA2 is a token standard (TZIP-12) on the Tezos network. FA2 provides an API standard for token transfers, balance inquiries, and managing token metadata.
Prerequisites:
- Download and install Node.js.and npm.
- Download and install Docker.
- Download the Github repository for this project.
- Sign up for a free Filebase account.
1. First, we need an image to use as an NFT. We’ll start by uploading an image to Filebase for us to use.
To do this, navigate to console.filebase.com. If you don’t have an account already, sign up, then log in.
2. Select ‘Buckets’ from the left side bar menu, or navigate to console.filebase.com/buckets.
Select ‘Create Bucket’ in the top right corner to create a new bucket for your NFTs.
3. Enter a bucket name and choose the IPFS storage network to create the bucket.
Bucket names must be unique across all Filebase users, be between 3 and 63 characters long, and can contain only lowercase characters, numbers, and dashes.
4. Next, select the bucket from your list of buckets, then select ‘Upload’ in the top right corner to upload an image file.
5. Select an image to be uploaded.
Once uploaded, it will be listed in the bucket.
6. You can view the object’s IPFS CID in the CID column, or you can click on your uploaded object to display the metadata for the object, which includes the IPFS CID.
Choose the method you prefer, and take note of the IPFS CID.
7. Open a command line interface and create a new directory for your project:
mkdir nft-tutorial
cd nft-tutorial
8. Install the @oxheadalpha/tznft
npm package:
npm install -g https://github.com/@oxheadalpha/nft-tutorial.git
9. Initialize the tznft tool:
tznft init
10. Confirm the initialization was successful by viewing the default active network.
The value returned should be ‘sandbox’:
tznft show-network
11. Next, bootstrap the Tezos network with the command:
tznft bootstrap
If this is the first time you are bootstrapping the sandbox network, Docker will automatically download the Flextesa docker image for use in the project.
12. Now it’s time to mint an NFT token. The command syntax for minting is as follows:
tznft mint <owner_alias> --tokens <token_meta_list>
Tznft comes with 2 default accounts for use — ‘bob’ and ‘alice’. For example, to mint an NFT called ‘Filebase Robot’ that is owned by the default account ‘bob’, you would use this command:
tznft mint bob --tokens '0, T1, Filebase Robot'
This command will return the NFT contract’s token ID. Take note of this for the next step.
13. To inspect the NFT contract and the associated token metadata, we can use the following command syntax:
tznft show-meta --nft <nft_address> --signer <alias> --tokens <token_id_list>
For example, to view the NFT contract for the contract created in the last step, the command would be:
tznft show-meta --nft E6S9t44fKR9Uo5KT1XP3RrAfqHvHXu9Cy7fh --signer bob --tokens 0 1
14. To inspect the token balance for our NFT contract, we can use the following syntax:
tznft show-balance --nft <nft_address> --signer <alias> --owner <alias> --tokens <token_id_list>
For example, to view the balance of the NFT we just created for the account bob, we can use the command:
tznft show-balance --nft E6S9t44fKR9Uo5KT1XP3RrAfqHvHXu9Cy7fh --signer bob --owner bob --tokens 0
The output should resemble the following:
querying NFT contract E6S9t44fKR9Uo5KT1XP3RrAfqHvHXu9Cy7fh using balance inspector H1ytG7saMZ34sfdKT1Pezr7JjgmrPcPhpkbk
requested NFT balances:
owner: tSZAXWvGsGwVJqUtz1YPSCGWXwBdTncK2aCc token: 0 balance: 1
15. Now let’s create an NFT with external metadata using the IPFS CID we recorded in the beginning of this tutorial from our Filebase upload.
To use the IPFS CID, we’ll add a fourth parameter to our token mint command:
tznft mint bob -t '0, Filebase, Filebase Robot, A44RPciW5pM4iyqRGQmRyTc9KbD7ZSkmEf4e7fk6rhbyvj'
Then, we can inspect the new token’s metadata to see the IPFS CID listed:
tznft show-meta -s bob --nft 3w1x23oiC31B8KT1SgzbcfTtdHRV8qHNG3hd --tokens 0
Which will return the following output:
token_id: 0 symbol: Filebase name: Filebase Robot extras: { ipfs_cid=A44RPciW5pM4iyqRGQmRyTc9KbD7ZSkmEf4e7fk6rhbyvj }
You can view the IPFS File by using the Filebase IPFS Gateway with the IPFS CID. For example, to view this image, you can go to:
https://ipfs.filebase.io/ipfs/A44RPciW5pM4iyqRGQmRyTc9KbD7ZSkmEf4e7fk6rhbyvj
16. Up until now, we have used the sandbox network for these commands.
You can connect to different Tezos networks by using the command:
Tznft set-network [network-name]
From here, you can create and mint NFTs right from the command line on any of the Tezos networks.
Want to learn more about Filebase? You can sign up for a free account today to get started with IPFS.