Getting Started Building NFT Contracts

(image from @distinctmind)

NFTs are a big topic and there are many ways to learn about them.

Here's an overview of NFTs, plus resources for getting started with NFT development on Ethereum, Polygon and other EVM blockchains.

A video is available from my interview on the "Web3 Kickoff Show" which includes an NFT overview, a Q&A session, and an introduction to NFT engineering topics discussed in this post.

In this post I'll give:

How I got started: NFT as gateway drug to Web3 engineering

An NFT was my first serious introduction to Web3 and it kicked off pursuing Web3 full-time.

I was attending a CascadiaJS 2021 workshop in November about adding a web UI to a smart contract in Solidity. I knew the front-end well, but what's a smart contract and Solidity? And there happened to be some members of Developer DAO attending/presenting at the conference. What's the Developer DAO?

If you want to join or learn more about Developer DAO, which a great organization for networking and building Web3 projects: What is Developer DAO?

After much searching around, I was able to discover the need to acquire an NFT for admission to the Developer DAO and access to its Discord. These Devs for Revolution NFTs were SVGs that only showed a list of key/value attributes (not the actual image) and there was a separate website for previewing what these NFTs would visually look like.

It turned out a month or two later, I would decide to join the Derivatives team who were building the actual visual versions of these NFTs. "Pixel Devs" would be my first official Web3 project. More info below.

What is an NFT?

"Fungibility is the ability of a good or asset to be readily interchanged for another of like kind. Like goods and assets that are not interchangeable, such as owned cars and houses, are non-fungible." (Definition of Fungibility)

A non-fungible token (NFT) is similar to a collector's item, or a ticket for a seat at an event, or even a car - it's a unique way of identifying "ownership" of a specific item that are not easily interchangeable. A dollar bill is an example of the opposite (a fungible token) which can easily be exchanged for other dollar bills.

Having an NFT on the blockchain provides public proof of ownership, which can then lead to interesting digital experiences such as gating access to a community (as mentioned in the case of joining the Developer DAO), or owning a collectible that you can also sell/trade.

What are some interesting uses for NFTs?

What is a Smart Contract?

Smart Contracts are the code you write and deploy to a blockchain.

I started developing contracts on the Polygon blockchain, which is faster and less expensive than Ethereum, but uses the same Solidity Smart Contract tech. There are many other blockchains that support Solidity contracts.

I'll refer to the family of blockchains that run the Ethereum Virtual Machine (which runs Solidity code) as EVM.

How do NFT contracts work behind-the-scenes?

Now that you know what an NFT is and what a Smart Contract is, let's walk through putting these concepts together.


Before jumping into code, note that NFTs can be created without writing code as well!

I'm an engineer, so I'm interested in learning about and creating smart contracts on say Ethereum or Polygon.

Here are just a few non-coding options for creating NFTs:

  • a marketplace like OpenSea (for minting on Ethereum, Polygon and a growing set of blockchains). See Create.
  • a marketplace like Tezos' objkt. See How to mint your first Tezos NFT on objkt.com.
  • via tools to generate and publish NFTs. For example on Solana, NFTs are created via a centralized program and ecosystem called Metaplex. See Creators section.

Ok, jumping into code now!

Let's walk through my smart contract starter template which:

PixelDevs

PixelDevs image

Read more about the project here at Launching Pixel Devs NFT on Polygon.

The source code is available at github.com/Developer-DAO/pixel-avatars. See the (collection on OpenSea) Note that minting these requires you own a Devs for Revolution NFT, which is the NFT for joining the Developer DAO.

This is good example of an Upgradeable contract, and as mentioned in the blog post, an innovative way to call Web3 services with the flexibility of using a Web2 server. In this case, it's to validate NFT ownership on Etherum to then mint on Polygon.

This is also an example of connecting the web UI to the smart contract.

Deployment and testing is also documented.

Developer DAO for Ukraine (Donation site)

Developer DAO for Ukraine image

Read more about the project here at Developer DAO for Ukraine. The source code is available at github.com/Developer-DAO/ukraine-donation-nft.

This is a good example of the power of Access Control and Roles as well as metadata needed to support OpenSea, and setting up Royalties. This is also an example of tiered-based pricing - six different types of NFTs, each with its own price point and image.

This is also an example of connecting the web UI to the smart contract.

Deployment and testing is also documented.

In Closing

There is a lot to learn about Web3, which is a challenge, but also an opportunity to experiment and shape the technologies and projects coming tomorrow.

Appendix A: Additional Resources

Appendix B: Ethereum-based NFT Projects

Here are some Ethereum NFT projects I found interesting.