Cointime

Download App
iOS & Android

How To Make Your Own NFTs On Flow

Written by: Nicholas Cantone, Agile Software Engineer, TribalScale

With blockchain technologies gaining immense popularity in recent years, it’s likely you’ve heard the buzz about non fungible tokens, or NFTs. Unfortunately, the inner workings of NFTs seem to be hidden behind a veil of complex blockchain concepts filled with technical jargon. Luckily for you, by the end of this blog post you will have gained a much deeper understanding of how these NFTs are made.

Today, we will be diving into NFTs on the Flow blockchain. If you aren’t familiar with blockchain technologies here is a good article by the verge to get you started. In brief, Flow was created in 2020 by Dapper Labs to meet their own growing demands for an efficient platform to host their immensely popular blockchain-based game, CryptoKitties. The language we use to interact with the Flow blockchain is called Cadence. The following section of this blog will explain key cadence concepts and the final portion will bring all those concepts together and show you how to make your very own NFT from scratch.

Cadence Concepts

Resources

Cadence is a resource-oriented programming language meaning that resources play a huge part in any Flow project. But what are they and why are they so great?

Well… resources are a type in cadence, but you can think of them as a highly secure and unique container for information (similarly to objects in javascript or structures in C). These resources have fields or functions associated with them, like in the code example below:

What makes resources so secure is the restrictions that are placed on them. (if you don’t believe me, check out the docs) “[Resources] can only exist in one location at a time and must be used exactly once”, therefore, resources are unique (kind of like NFTs) and can’t ever be created and unused or go out of scope and be lost forever.

The way we use resources is by either moving them, or destroying them. You can see how these restrictions are so useful in the context of NFTs. For instance, if I create an NFT resource, I can’t lose track of it. I have to transfer it into another user’s account, save it into mine, or explicitly destroy it. Here is a small code excerpt that highlights the creation and moving of resources in a function:

Smart Contracts

Moving on to one of the most important tools in any blockchain developers tool shed, smart contracts. They’re essentially like recipes. Much like recipes they are divided into their state (list of ingredients) and logic (cooking steps). The state of the contract lives in the blockchain and can be thought of as the attributes of our contract. The state of our contract will also hold any type definitions (such as resources). The logic portion of the contract consists of functions which simply tell you how to view or modify the state.

If you’re wondering how you can deploy your very own contract to the Flow blockchain, the first step would be to create an account.

Your account is basically your little storage allocation of the blockchain. In your account, you can store all your contracts along with any other resource, in the final section of this blog we’ll explore how resources are saved to storage and made publicly accessible. Your account will have an address associated with it which will be extremely important for accessing items in your storage. Think of your home address, it would be really hard to order from Amazon if you forgot your postal code or your street number.

Here is a link to get you started (you’ll also need the flow cli installed).

Transactions and Scripts

The only way you can interact with your contract (or any data on the blockchain for that matter) is through scripts or transactions and the conceptual difference between the two is quite simple. Scripts can only read from the blockchain, whereas transactions can read and modify data from the blockchain.

Common scripts would be used to get the metadata of an NFT, get a list of all the current owners of your NFTs or to get a list of the past owners. Common transactions could be to mint an NFT, setup a consumer’s account or transfer ownership of an NFT.

While the transactions and scripts you write are the ones doing all the heavy lifting, they are always implementing contracts. For instance, the act of minting an NFT through a transaction will always require the use of functions (such as createToken) that you define in your contract.

One last point that I will mention is that since transactions are modifying data on the blockchain there is a ‘gas fee’. Therefore every time the transaction is executed the person who executed it must pay a small fee. However there is a test environment that exists on Flow for development purposes.

Making an NFT

FLOW NFT standard

To make your own NFT all you need is a contract with a few special attributes. To make sure there isn’t any confusion, Flow created a contract that defines a standard that all non fungible tokens must meet. These standards are implemented using interfaces, click here to learn more. For your contract to be up to Flow’s standards it needs the following.

Your contract must have

  1. A NFT resource (and a function to create one createToken)

The NFT resource that your contract must contain has fairly few required attributes. As long as your NFT resource has an ‘id’ field it is good to go!

(code from flow’s NonFungibleToken.cdc contract)


2. A collection resource (and a function to create one createEmptyCollection)

The collection on the other hand is a little more complex. As we know, resources are unique, however, this poses a problem to users who would like to own more than one of our NFTs. Flow’s solution is the Collection resource. A collection, is simply a container built to store multiples of our NFT resource (every NFT has their own unique collection so we must define ours!).

Our collection resource must have an ownedNFTs field which stores a list of all the NFTs being stored in that collection. A withdraw function which allows us to remove NFTs from the collection. A deposit function which lets us add an NFT into the collection. A getIDs function which returns a list of all the IDs of the NFTs in the collection. Last but certainly not least, there must be a borrowNFT function which takes in an ID and returns the NFT which posses that ID.

(code from flow’s NonFungibleToken.cdc contract)


3. A publicCollection resource interface.

Lastly, we must have a publicCollection resource interface. Interfaces are a more complicated topic so I’ll give more of a conceptual overview of what this resource accomplishes. In sum, a resource interface is a restricted version of a resource. Our publicCollection will be a version of our collection that anyone will be able to access, so we want to remove some functionality to make sure that someone can’t just withdraw all of your NFTs.

Our publicCollection will restrict our Collection to 3 functions, deposit, getIDs and borrowNFT. As a clarification, borrowNFT only returns a reference to the NFT so don’t worry about someone borrowing your favourite NFT and messing it up.

(code from flow’s NonFungibleToken.cdc contract)


Finally, with these resources and resource interface your contract will be up to the Flow NFT standards! If you want to have some Metadata associated with your token make sure to view this contract to see how you can give your token some standardized Metadata which will allow you to post it on a marketplace and make some royalties!

Mint transaction

To mint a NFT there are a few steps, as we now know NFTs need to reside in a collection, but where do these collections reside? Well, if you recall the ‘Smart Contracts’ portion of this post, I mentioned that accounts are essentially storage, therefore step 1 of minting an NFT is to save an empty collection to our storage using our createEmptyCollection function.

In the following code excerpts I’ll be using ‘MyNFT’ as a placeholder for the name of an NFT contract:

The step 2 was foreshadowed in the previous section, we must link a publicCollection to a public section of our storage (paths beginning with /public are public and /storage are private).

Step 3 is to borrow the collection we just created.

Finally, we create an NFT using our createToken function and deposit it into our collection using our deposit function that we defined in our Collection resource.

And with that our minting transaction is complete. Hopefully you have gained a good conceptual understanding of the NFT creation process through this post and if ever you want to explore the world of NFTs on the flow blockchain there is no better time to start than the present! Even as a developer I found the world of NFTs very intimidating at first but once you get started you’ll be amazed at what you can do!

NFT
Comments

All Comments

Recommended for you

  • Zuckerberg Directs Meta to Develop Prediction Market Application

    On June 24, The New York Times reported that Zuckerberg has instructed Meta to develop a prediction market application. The internal name for the application is 'Arena', which is similar to Polymarket or Kalshi.

  • U.S. Senate Passes Resolution Aiming to Limit Trump's War Powers Against Iran

    On June 24, the U.S. Senate passed a resolution regarding war powers related to Iran, with 50 votes in favor and 48 against, following a similar approval by the House of Representatives. This marks the first time such a resolution has been approved by both chambers of Congress. The resolution calls for the president to end military actions against Iran without a declaration of war or authorization of force from Congress. However, since this resolution is a joint resolution of Congress, it is not legally binding and does not require the president's signature, thus serving mainly a symbolic purpose.

  • AI Smart Terminals Experience Full Explosion

    On June 23, according to CCTV Finance, at the fourth Chain Expo, the original "Digital Technology Chain" was upgraded to the "Smart Technology Chain." This change in wording reflects that artificial intelligence is becoming the main character in the industrial chain. A newly established AI zone at the event gathered leading AI companies from both domestic and international markets, showcasing the entire chain from data and computing power to applications. Various AI products were on display, including AI glasses, smart cars with digital chassis, and humanoid robots that can play soccer. CCTV Finance reporters observed that the integration of artificial intelligence into the physical world is transitioning from mobile phones and computers to various new smart terminals. This year, the application of AI agents has also experienced a full explosion. Qian Kun, Senior Vice President of Qualcomm, stated that the empowerment of AI agents is leading to a significant upgrade cycle for existing terminal devices. China's industrial chain is very complete, and through continuous collaboration with Chinese partners, their products can quickly reach the market and gain global acceptance. Liu Xiangwen, Vice President of Alibaba Cloud Intelligence Group, noted that AI has evolved from mere chatting to becoming a productive force. The development of all stacks, whether GPU cloud or CPU, is progressing rapidly, and there is still greater potential ahead.

  • U.S. Stock Indices Experience Short-Term Rally

    On June 23, the Dow Jones Industrial Average rose by 0.07%; the S&P 500 index narrowed its decline to 0.77%, having previously fallen over 1.5%; the Nasdaq Composite index also reduced its drop to 1.17%, after having been down more than 2.3% at one point.

  • Vitalik: Ethereum Foundation Budget Cut by 40%, Shifting to Long-term Fund Model

    On June 23, Vitalik Buterin revealed that the Ethereum Foundation (EF) will reduce its budget by approximately 40% this year. According to its previously announced financial management plan, EF is transitioning from a model where it spends about 15% of its remaining funds annually to a model where it will spend about 5% annually after 2030, moving towards a long-term donation-oriented organization. To this end, EF will adjust its multi-client model, relying more on AI-assisted formal verification. The PSE privacy and scalability exploration team will shift from 'exploration' to a focus on building around zero-knowledge proofs. The scale and losses of Devcon events will be reduced, and large projects beyond Ethereum itself will also decrease. EF's institutional work will focus on smaller-scale, replicable CROPS-friendly deployment cases.

  • Huo Qigang: In the AI Era, Our Own Judgment is Key

    On June 23, according to CCTV Finance, Huo Qigang stated that over the past year, the topic of AI has been overwhelming, shifting from 'not using AI' to 'having to use AI,' making him acutely aware that 'not participating will lead to elimination.' As a father, Huo Qigang candidly expressed the dilemma of whether parents should 'control' or 'assist' when their children use AI. He mentioned that he has already begun to assist with AI in his work, but emphasized that using AI does not mean bypassing the thinking process; one must rely on their own experience, thought, and logical judgment, and cannot simply replicate AI outputs.

  • NVIDIA's Market Value Falls Below $500 Billion

    On June 23, NVIDIA (NVDA.O) saw its market value drop below $500 billion, with a latest decline of 2.6%.

  • U.S. Manufacturing Activity Surges Beyond Expectations, But Factory Employment Falls to Six-Year Low

    Driven by companies placing orders in advance to prevent shortages and price increases, U.S. manufacturing activity expanded again in June. However, factory employment fell to a six-year low, primarily due to rising operational costs influenced by conflicts in the Middle East. The preliminary S&P Global Manufacturing PMI for June rose to 55.7 from 55.1 in May, marking the highest level since May 2022, while economists surveyed by Reuters had previously expected the index to drop to 54.8. The increase in the manufacturing PMI, combined with a rise in the services PMI from 50.7 in May to 51.3, contributed to a composite PMI output index increase from 51.5 last month to 52.2. The rebound in the services PMI is partially attributed to the World Cup events jointly hosted by the U.S., Canada, and Mexico.

  • Microsoft Completes Data Center Construction in Wisconsin

    Microsoft (MSFT.O) announced the completion of its first data center construction in Mount Pleasant, Wisconsin, USA.

  • Goldman Sachs: Brazilian Central Bank Expected to Alternate Between Rate Cuts and Holding Steady

    On June 23, Goldman Sachs' Alberto Ramos stated that the Brazilian Central Bank may alternate between pausing rate cuts and lowering its benchmark Selic rate. Last week, the Brazilian Central Bank reduced the Selic rate from 14.5% to 14.25%, and its next steps remain unclear. Amid sticky inflation and risks of economic slowdown, the meeting minutes provided some insight into the central bank's thinking. Ramos noted that intermittent rate cuts 'will lead to milder output fluctuations, with inflation converging to target levels by the first quarter of 2028.' He added, 'Overall, in the short-term trade-off between growth and inflation, Copom is more inclined to protect economic activity rather than adopt a more aggressive inflation-focused strategy.'