durneja.eth

Posted on Sep 13, 2022Read on Mirror.xyz

How to build NFTs in the NEO / N3 blockchain setup and what is the NEP-11 protocol [Part 1]

This article is part of a two part series of how to build your own NFT project on the NEO N3 blockchain ecosystem in a language of your choice. I lay stress on “language of your choice” because the NEO blockchain offers this unique ability where instead of learning a new obscure language, you can bring your ideas to life in a language you are comfortable with, be it Java, C#, or Python. In the first part, we would look at it from a slightly theoretical perspective, understanding NFTs from a NEO perspective, understanding the NEP-11 protocol and some implementation considerations. In the second part, we would take the plunge and look at actual code and implementation specifics that will help you to get your first NFT project ready to be shipped.

Build NFTs with NEO

The assumption here is that you are at least somewhat familiar with what NFTs are, probably minted or traded a few, are down to writing code and have some familiarity with the NEO ecosystem. If the answer to any of the questions is No, fear not, I’ll include some reading references at the end of the article to cover some of these aspects.

What is NEP-11

NEP-11 is a proposal that outlines the standard for writing NFTs in NEO. The NEP in NEP-11 stands for NEO Enhancement Proposal and contains standard definitions and enhancements for developing on the NEO Ecosystem. Just like NEP-11 is the standard for NFTs or Non-Fungible Tokens, NEP-17 is the standard defining Fungible Tokens in NEO and which supersedes the NEP-5 definitions.

Now that we understand what is NEP-11 here is a link to the actual proposal. It contains the standard definitions, and protocol methods with samples in a few cases as well as contains a reference implementation for the same.

https://github.com/neo-project/proposals/blob/master/nep-11.mediawiki

The NEP-11 Protocol

In this section we will zoom in to look at the protocol definition and some of the key interface methods that we must necessarily implement and be very careful about their implementations so as to avoid any potential issues later, security or otherwise.

The basics

The first few methods we would look at are fairly straightforward and define the key elements of the NFT. They are symbol, decimals, and totalSupply.

The symbol method gives an identity to the NFT project and should return a string of upto 8 characters with no whitespaces. Examples - MYNFT, YOLONFT, etc.

The decimals method should return the number of decimals up to which the NFT token would be divisible. A value of 0 should be returned if the token is not intended to be fractionalized.

The totalSupply method should return the total number of tokens that are currently outstanding or in circulation. This should be updated at any such event where the supply is affected like mint, burn, etc.

Tokens and Ownership

These methods would include methods that either give information about the tokens or about the ownership details of those tokens both from an owner perspective as well as the token’s perspective. These methods would include - balanceOf, tokensOf, ownerOf. There are couple of other methods as well that are option but would be helpful to include in your smart contract for completion - tokens, properties.

The balanceOf method should return the number of tokens that are held by a particular address.

The ownerOf method should return the address of the holder of that particular token. The input should be the token id whose owner we are interested to know about.

The tokensOf method should return an iterator of all the tokens that are held by the particular address which is sent as the input.

The tokens method should return an iterator of all the tokens that are currently stored in the smart contract.

The properties method should return key-value pairs of the various properties or attributes of the particular token whose identifier is sent as an input. This is an important method as it would return the metadata that NFT viewers, and marketplaces would use to display the token visually. The attributes may include name, tokenURI, image, description, and any other attributes relevant to the project mechanics.

Transactional

Here we look at some of the interactive aspects of the NFT. Most important of these is the transfer method.

The transfer method as is obvious allows the token holders to transfer their tokens to another address/holder. The corresponding maps storing the ownership details should be updated accordingly.

There is also a specified transfer event that needs to be fired when a transfer gets executed and also in case of minting and burning events.

Another method that should be implemented when the contract should accept NFT tokens is the onNEP11Payment method.

Others

burn and mint are some of the other functions that aren’t specifically part of the protocol but would be helpful to achieve certain functionality as part of the NFT project. Minting and Burning methods (just like the others) could have an owner only check so that non-owners are not able to mint the tokens directly.

Another method that should be implemented especially when the NFT Tokens should be minted when fungible tokens are transferred to it is the onNEP17Payment method. You can have logic to set and check for the base price that is received as part of the transfer and based on that mint the token for the account that transferred the tokens.

You could have other owner-restricted methods to control and administer the tokens like controlling the base prices, retrieving or transferring funds, overriding mints, total supply, etc. Implement them depending on your particular use cases.

Next Step: Build

Hopefully the overview of NFTs and the background information on the NFT protocol, i.e the NEP-11 proposal should have given a fair understanding of what is needed to build out an NFT project but we are just getting started. In the next and final part of the article, we would actually look at some code and methods that would take you further in your journey to launch your first NFT project.

References

https://future.com/nft-canon/ The NFT Canon is an amazing resource catering to a broad section of people who intend to understand or do more with non-fungible tokens.

https://neo.org/dev#overview This is the NEO Developer page. Check out the various tools and frameworks relevant for your language as well as examples and tutorials to help you get started.

https://docs.neo.org/docs/en-us/index.html Contains all documentation around N3 with basic NEO concepts, guides, API specifications, and everything in between.

subscribe://

NEO