Web3 NFTs – Build and List NFTs Using Python, Openzeppelin, Pinata

Token economy is a hot vocabulary in the business world. Two main types of tokens, which is fungible and non-fungible tokens. NFTs (non-fungible token) is a unique digital identifier that cannot be copied, substituted, or subdivided, that is recorded in a blockchain. It provides a public certificate of authenticity or proof of ownership. 

Assets, notably intangible assets can be evaluated continuously and publicly in an absolutely transparent and disruptive way, compared to traditional intangible asset valuation, although NFT ownership itself has no inherent legal meaning.

In this article, I would go through how to build your Web3 NFT collections using Python, Openzeppelin, and Pinata, which can be listed on Opensea markets.

web3 nft

Token economy is a hot vocabulary in the business world. Two main types of tokens, which is fungible and non-fungible tokens. NFTs (non-fungible token) is a unique digital identifier that cannot be copied, substituted, or subdivided, that is recorded in a blockchain. It provides a public certificate of authenticity or proof of ownership. 

Assets, notably intangible assets can be evaluated continuously and publicly in an absolutely transparent and disruptive way, compared to traditional intangible asset valuation, although NFT ownership itself has no inherent legal meaning.

In this article, I would go through how to build your Web3 NFT collections using Python, Openzeppelin, and Pinata, which can be listed on Opensea markets.

Ingredients on Web3 NFT – Build NFTs Using Python, Openzeppelin, Solidity

Table of Contents

NFT Smart Contract

As well as a fungible token, we need to start by developing the smart contract code in NFT development. 

First thing first, we can make well use of existing modules out there, such as Openzeppelin, which can save some time to develop common functions. Please be sure to add the dependencies in the brownie-config.YAML as well. If you have any questions related to this, please refer to other articles in the Easy2Digital web3 collection.

// contracts/GameItem.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

As you can see ERC721, which is different from the fungible token ERC20, it’s the standard non-fungible token. Thus, under this module, we create a contract using ERC721.

  • There are two parameters in ERC721 here, one is the full name and the other is the short name of the NFT created. And it starts with tokens as you would see in the created collection including a plus function when you create the NFT one after one.

contract SimpleCollection is ERC721 {

   uint256 public to encounte;

   constructor() public ERC721("LouisNFT", "LVnft") {

       tokenCounter = 0;

   }

   function createCollection(string memory tokenURI) public returns (uint256) {

       uint256 newTokenId = tokenCounter;

       _safeMint(msg.sender, newTokenId);

       _setTokenURI(newTokenId, tokenURI);

       tokenCounter = tokenCounter + 1;

       return newTokenId;

   }

}

  • Then, each new NFT has a unique token URI and token ID. The token ID is hashed by uint256 based on the token counter number. And the token URI basically includes all material information regarding the NFT, which includes the image. I will go through it in a moment.

Metadata

Metadata is a JSON file that allows applications like OpenSea to pull in rich data for digital assets and easily display them in-app. Here are the elements included in a basic metadata file as follows:

web3 nft

Storing data on the blockchain can be very expensive, except for those script files. Nevertheless, images, videos, and audio which can be large sizes of material can be pricy stored on the blockchain.

So normally we can leverage using decentralized storage such as IPFS. IPFS or inter-planetary file system is a protocol, hypermedia, and file-sharing peer-to-peer network for storing and sharing data in a distributed file system.

There are two ways basically to upload your NFT materials to IPFS. One is to install a local IPFS environment to interact with the IPFS network. The other is to run through a 3rd party platform, such as Pinata.

Upload the NFT image and JSON file to Pinata for generating a token URI.

First thing first, the 1st step is to create a Pinata account and prepare the image you like to convert into NFTs.

Then, upload the image as the file onto Pinata and then you can get a CID key from this materials. The key would be used in a moment to create a JSON file.

web3 nft

Additionally, as the token URI is a JSON file, the next step is to add all information related to NFT in a JSON file. Here is a sample using VSC as follows:

  • Name
  • Image: The IPFS URL structure, https://ipfs.io/ipfs/ + image CID key (Generated just now)
  • Description
  • attribute

Last but not least, once the JSON file is ready, please go back to Pinata and upload the JSON and generate the JSON file CID key. Here is the sample of the final token URI of the IPFS URL.

https://ipfs.io/ipfs/QmV8rPonNpVaKnH2ri826AWqJ5XxeKYdeJupjKch4kA1UK?filename=NFT1.json

Opeasea Account Integration

OpenSea is the world’s first and largest web3 marketplace for NFTs and crypto collectibles. Browse, create, buy, sell, and auction NFTs using OpenSea. For any NFTs, listing to a marketplace is very common no matter it’s for the purpose to sell or not. Notably, most companies leverage this to build brand awareness and assist to implement loyalty programs as well.

web3 nft

For this case, we can simulate the NFTs listing process by using opensea testnet. Creating an opeansea testnet account is totally free. In our case, we would use MetaMask to list NFTs. So please be sure to sign up the opensea test account connecting with the MetaMask testnetwork account as well.

For the opeansea testnext NFT URL, basically, it has two variables which are the cryptocurrency network and the 

For the opeasea listing URL, the structure has two variables and here is the sample

https://testnets.opensea.io/assets/goerli/0x8eeb73f75e6d80a6a21302d1ec36d0ead0ceb295/0

  • Network address: goerli/0x8eeb73f75e6d80a6a21302d1ec36d0ead0ceb295
  • Token Counter: 0 (This number represents the order of the NFT, 0 means it’s the first one)

We’ll use this in a moment on the Python deployment scripts.

Python Deployment Script

Apart from importing the brownie and assistscript modules as well as building fungible token, NFT deployment needs two variables. They are the sample_collection_URI and OPEASEA_URL

sample_collection_URI = "https://ipfs.io/ipfs/QmV8rPonNpVaKnH2ri826AWqJ5XxeKYdeJupjKch4kA1UK?filename=NFT1.json"

OPENSEA_URL = "https://testnets.opensea.io/assets/{}/{}"

Then in the main function, we need to use the createcollection functions as created earlied in the NFT smart contract

def main():

   account = get_account()

   Simple_Collection = SimpleCollection.deploy({"from": account})

   tx = Simple_Collection.createCollection(

       sample_collection_URI, {"from": account})

   tx.wait(1)

Brownie-config, ENV, and assistScripts

As well as fungible token development, we need to add on these scripts. For more details, please refer to these articles

Use Infura and MetaMask in Python Scripts to Deploy Web3 Smart Contracts on a Real Ethereum BlockChain Network

Brownie FundMe Smart Contract Deployed on Ethereum Using Python & Web3

Once the scripts are ready, we can run the scripts on the specific network and the result here shows it’s done and the NFT has been listed on the marketplace.

Brownie run scripts/deploy_NFTCreate.py –network goerli

web3 nft

Full Scripts of Building NFTs Using Python, Openzeppelin, Pinata

If you are interested in Web3 NFTs – Build and List NFTs Using Python, Openzeppelin, Pinata, please subscribe to our newsletter by adding the message “Web3.0 tutorial 7”. We would send you the script immediately to your mailbox.

I hope you enjoy reading Web3 NFTs – Build and List NFTs Using Python, Openzeppelin, and Pinata. If you did, please support us by doing one of the things listed below, because it always helps out our channel.

Leave a Reply

Your email address will not be published. Required fields are marked *