TL;DR: This article provides step-by-step instructions on how to deploy, mint and import an NFT using Hardhat, Swarm Desktop App and Metamask. You will learn how to deploy an NFT contract on Gnosis, mint an NFT to your wallet address, store the NFT image and metadata on Swarm, and import your NFT in Metamask. The NFT example repo used in this article is intended to serve as an easy reference that can then be built upon to create collections of NFTs that store their data, decentralised, in the Swarm.
On NFTs
An NFT (Non-Fungible Token) is a type of digital asset that represents ownership or proof of authenticity of a unique item or piece of content, such as artwork, music, videos and even tweets. Unlike fungible tokens, such as cryptocurrencies, which are interchangeable and have the same value, each NFT is unique and can have its own distinct value, based on its rarity, historical significance or popularity. NFTs are typically stored on a blockchain, which provides a decentralised and tamper-proof record of ownership and transaction history. This makes NFTs an exciting new way for creators and collectors to monetise and trade digital assets, while also providing a new level of transparency and authenticity in the digital world.
Prerequisites
Before we get started, make sure you have the following prerequisites:
node = 16
- Swarm Desktop running a light node funded with some BZZ and XDAI
Deploying an NFT Contract on Gnosis
The first step to creating an NFT is to deploy an NFT contract on Gnosischain. Here’s how to do it:
Clone repository and install packages
Let’s clone the NFT Example repository and install the packages
git clone https://github.com/rampall/nft-example.git
cd nft-example
npm install
Deploy NFT contract
Steps to deploy the NFT contract:
- Copy the contents of
.env.example
in the project root to a new.env
file :cp .env.example .env
- Create a new account in Metamask and fund it with a small amount of XDAI (XDAI 0.10 is enough) on Gnosischain; this will be your deployment account.
- In Metamask, click the three dots next to your account address and select “Account Details”, then “Export Private Key”.
- Enter your password and then copy the private key into your
.env
file afterGNOSIS_PRIVATE_KEY=0x
(it should have an 0x prefix). - Deploy your contract using the following command:
npx hardhat run --network gnosis scripts/deploy.ts
- The NFT contract address should be printed in the output message. Copy and paste it into
.env
afterNFT_TOKEN_ADDRESS=0x
.
Mint NFT
- Start up Swarm Desktop.
- Buy a postage stamp batch by following these steps. This should give you a Batch ID.
- Copy the Batch ID value into the
.env
afterPOSTAGE_BATCH_ID=
- Create another new account in Metamask and copy the address into
.env
afterNFT_TO_ADDRESS=0x
; this is the address that will receive your NFT. - Mint your NFT using the following command:
npx hardhat run --network gnosis scripts/mint.ts
Import NFT
- In Metamask, with your
NFT_TO_ADDRESS
account selected, select network ‘Gnosis Chain’, clickNFT
then scroll down and selectImport NFTs
. - Copy the NFT contract address from step 6 into the
Address
field and input0
as theToken ID
. - You should be able to see your own Beelon Musk NFT in your Metamask wallet; keep it or send it to a friend!
- Replace
{{0x...}}
in this url with your contract address from step x and open the linkhttps://gnosis.nftscan.com/{{0x...}}/0
. You should be able to see your Beelon Musk NFT on nftscan!
Congratulations đź‘Ź! You’ve successfully created an NFT and stored its metadata on Swarm. You can use this repo as a starting point to create collections of NFTs that store their data, decentralised, in the Swarm.
References
Discussions about Swarm can be found on Reddit.
All tech support and other channels have moved to Discord!
Please feel free to reach out via info@ethswarm.org
Join the newsletter! .