NFTs or Non-Fungible Tokens have been all the rage this year. Most of us know what they are and how they work, but if you haven’t caught onto the NFT buzz, you can get upto speed by reading our article on ‘What are Non-fungible tokens or NFTs?’. These tokens have proven to be very useful when it comes to trading assets like digital artwork, music, and other types of media. However, many collectors and entrepreneurs are still unsure about how to create NFTs or non-fungible tokens.
The popularity of NFTs has been skyrocketing this year. The NFT Report 2020 published by L’Atelier BNP Paribas and Nonfungible.com has been a testament to this as they stated that the NFT market tripled in size overall last year, and its total value rose to more than $250 million. In this article, you will be able to get a better understanding of how to develop your own NFT token in a simple step-by-step format.
If you are looking to create a non-fungible token, the first step that you will need to take is to figure out which marketplace you want to list the token on. This is because the marketplace you choose will have a direct impact on how and where you will have to create the NFT. Although there are ways to develop an NFT from scratch, it is usually suggested to use a platform that is dedicated to NFT development. This is generally the easiest way to develop an NFT.
While deciding on a platform for NFT creation, it would be useful to look into which blockchain the platform uses. There are myriad blockchains that support NFT creation, including Ethereum, the Binance Smart Chain, Flow by Dapper Labs, Tron, EOS, Polkadot, Tezos, Cosmos, and WAX.
There are a large variety of blockchains that can be used for NFTs out in the market today. This is why you will probably have some trouble deciding which one would work best for you. A few key considerations that you should have before taking a concrete decision include-
Currently, Ethereum is the most popular blockchain service for NFT issuance. A few other popular blockchains include:
Every blockchain will have a distinct NFT token standard, wallet service, and marketplace. For example, if you develop NFTs on top of the Binance Smart Chain, you will only be able to sell them on platforms that support Binance Smart Chain assets. This means you wouldn’t be able to sell them on other marketplaces.
Reach out to us today, to discuss your projectNeed help with blockchain development?
In this article, we’ll discuss how to create an NFT token in the ERC-721 standard. This standard allows creating tokens that are unique and can have different values. The difference in tokens can be attributed to their age, rarity, etc. All NFT tokens have a uint256 variable called tokenId. For any ERC-721 Contract, the pair contract address and uint256 tokenId must be globally unique. dApps built using ERC-721 can have a “converter” that uses the tokenId as input and outputs an image or digital assets. ERC-721 facilitates functionalities like transferring tokens between accounts, getting the current token balance of an account, getting the owner of a specific NFT token, and also the total supply of the token available on the network. If a Smart Contract implements the following methods and events it can be called an ERC-721 NFT Contract.
function balanceOf(address _owner) external view returns (uint256); function ownerOf(uint256 _tokenId) external view returns (address); function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable; function safeTransferFrom(address _from, address _to, uint256 _tokenId) external payable; function transferFrom(address _from, address _to, uint256 _tokenId) external payable; function approve(address _approved, uint256 _tokenId) external payable; function setApprovalForAll(address _operator, bool _approved) external; function getApproved(uint256 _tokenId) external view returns (address); function isApprovedForAll(address _owner, address _operator) external view returns (bool);
event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId); event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId); event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
A standard can make it simple to inspect any ERC-721 Token Contract on Ethereum. For this, you just need a Contract Application Binary Interface or ABI to create an interface to any ERC-721 token. Below, you can see how to use a simplified ABI.
First, make sure you have installed Web3.py Python library:
$ pip install web3
from web3 import Web3 from web3.utils.events import get_event_data w3 = Web3(Web3.HTTPProvider("https://cloudflare-eth.com")) ck_token_addr = "0x06012c8cf97BEaD5deAe237070F9587f8E7A266d" # CryptoKitties Contract acc_address = "0xb1690C08E213a35Ed9bAb7B318DE14420FB57d8C" # CryptoKitties Sales Auction # This is a simplified Contract Application Binary Interface (ABI) of an ERC-721 NFT Contract. # It will expose only the methods: balanceOf(address), name(), ownerOf(tokenId), symbol(), totalSupply() simplified_abi = [ { 'inputs': [{'internalType': 'address', 'name': 'owner', 'type': 'address'}], 'name': 'balanceOf', 'outputs': [{'internalType': 'uint256', 'name': '', 'type': 'uint256'}], 'payable': False, 'stateMutability': 'view', 'type': 'function', 'constant': True }, { 'inputs': [], 'name': 'name', 'outputs': [{'internalType': 'string', 'name': '', 'type': 'string'}], 'stateMutability': 'view', 'type': 'function', 'constant': True }, { 'inputs': [{'internalType': 'uint256', 'name': 'tokenId', 'type': 'uint256'}], 'name': 'ownerOf', 'outputs': [{'internalType': 'address', 'name': '', 'type': 'address'}], 'payable': False, 'stateMutability': 'view', 'type': 'function', 'constant': True }, { 'inputs': [], 'name': 'symbol', 'outputs': [{'internalType': 'string', 'name': '', 'type': 'string'}], 'stateMutability': 'view', 'type': 'function', 'constant': True }, { 'inputs': [], 'name': 'totalSupply', 'outputs': [{'internalType': 'uint256', 'name': '', 'type': 'uint256'}], 'stateMutability': 'view', 'type': 'function', 'constant': True }, ] ck_extra_abi = [ { 'inputs': [], 'name': 'pregnantKitties', 'outputs': [{'name': '', 'type': 'uint256'}], 'payable': False, 'stateMutability': 'view', 'type': 'function', 'constant': True }, { 'inputs': [{'name': '_kittyId', 'type': 'uint256'}], 'name': 'isPregnant', 'outputs': [{'name': '', 'type': 'bool'}], 'payable': False, 'stateMutability': 'view', 'type': 'function', 'constant': True } ] ck_contract = w3.eth.contract(address=w3.toChecksumAddress(ck_token_addr), abi=simplified_abi+ck_extra_abi) name = ck_contract.functions.name().call() symbol = ck_contract.functions.symbol().call() kitties_auctions = ck_contract.functions.balanceOf(acc_address).call() print(f"{name} [{symbol}] NFTs in Auctions: {kitties_auctions}") pregnant_kitties = ck_contract.functions.pregnantKitties().call() print(f"{name} [{symbol}] NFTs Pregnants: {pregnant_kitties}") # Using the Transfer Event ABI to get info about transferred Kitties. tx_event_abi = { 'anonymous': False, 'inputs': [ {'indexed': False, 'name': 'from', 'type': 'address'}, {'indexed': False, 'name': 'to', 'type': 'address'}, {'indexed': False, 'name': 'tokenId', 'type': 'uint256'}], 'name': 'Transfer', 'type': 'event' } # We need the event's signature to filter the logs event_signature = w3.sha3(text="Transfer(address,address,uint256)").hex() logs = w3.eth.getLogs({ "fromBlock": w3.eth.blockNumber - 120, "address": w3.toChecksumAddress(ck_token_addr), "topics": [event_signature] }) # Notes: # - 120 blocks is the max range for CloudFlare Provider # - If you didn't find any Transfer event you can also try to get a tokenId at: # https://etherscan.io/address/0x06012c8cf97BEaD5deAe237070F9587f8E7A266d#events # Click to expand the event's logs and copy its "tokenId" argument recent_tx = [get_event_data(tx_event_abi, log)["args"] for log in logs] kitty_id = recent_tx[0]['tokenId'] # Paste the "tokenId" here from the link above is_pregnant = ck_contract.functions.isPregnant(kitty_id).call() print(f"{name} [{symbol}] NFTs {kitty_id} is pregnant: {is_pregnant}")
CryptoKitties Contract has some interesting Events other than the Standard ones.
Let’s check two of them, Pregnant and Birth.
# Using the Pregnant and Birth Events ABI to get info about new Kitties. ck_extra_events_abi = [ { 'anonymous': False, 'inputs': [ {'indexed': False, 'name': 'owner', 'type': 'address'}, {'indexed': False, 'name': 'matronId', 'type': 'uint256'}, {'indexed': False, 'name': 'sireId', 'type': 'uint256'}, {'indexed': False, 'name': 'cooldownEndBlock', 'type': 'uint256'}], 'name': 'Pregnant', 'type': 'event' }, { 'anonymous': False, 'inputs': [ {'indexed': False, 'name': 'owner', 'type': 'address'}, {'indexed': False, 'name': 'kittyId', 'type': 'uint256'}, {'indexed': False, 'name': 'matronId', 'type': 'uint256'}, {'indexed': False, 'name': 'sireId', 'type': 'uint256'}, {'indexed': False, 'name': 'genes', 'type': 'uint256'}], 'name': 'Birth', 'type': 'event' }] # We need the event's signature to filter the logs ck_event_signatures = [ w3.sha3(text="Pregnant(address,uint256,uint256,uint256)").hex(), w3.sha3(text="Birth(address,uint256,uint256,uint256,uint256)").hex(), ] # Here is a Pregnant Event: # - https://etherscan.io/tx/0xc97eb514a41004acc447ac9d0d6a27ea6da305ac8b877dff37e49db42e1f8cef#eventlog pregnant_logs = w3.eth.getLogs({ "fromBlock": w3.eth.blockNumber - 120, "address": w3.toChecksumAddress(ck_token_addr), "topics": [ck_extra_events_abi[0]] }) recent_pregnants = [get_event_data(ck_extra_events_abi[0], log)["args"] for log in pregnant_logs] # Here is a Birth Event: # - https://etherscan.io/tx/0x3978028e08a25bb4c44f7877eb3573b9644309c044bf087e335397f16356340a birth_logs = w3.eth.getLogs({ "fromBlock": w3.eth.blockNumber - 120, "address": w3.toChecksumAddress(ck_token_addr), "topics": [ck_extra_events_abi[1]] }) recent_births = [get_event_data(ck_extra_events_abi[1], log)["args"] for log in birth_logs]
Reach out to us today, to discuss your projectNeed help with blockchain development?
A detailed explanation of the creation of NFTs with the ERC-721 standard can be found here. In the next article, we’ll see how to list mint NFT tokens and list NFT tokens in NFT marketplaces.