Build a WEB3 app to mint unlimited NFTs… But should you?

FireshipFireship
Science & Technology4 min read24 min video
Jan 18, 2022|443,618 views
Save to Pod

Key Moments

TL;DR

Build a Web3 NFT minting app with Solidity, React, and Hardhat, exploring pros & cons.

Key Insights

1

Web3 NFT apps involve generating art layers, storing them on IPFS, and minting tokens via smart contracts.

2

Solidity, used for smart contracts, requires careful implementation of standards like ERC-721.

3

Hardhat provides tools for development, testing, and deployment of smart contracts.

4

Frontend development with React and ethers.js allows user interaction with the blockchain via wallets like MetaMask.

5

Storing NFT metadata and images off-chain on IPFS is crucial due to blockchain storage limitations.

6

Testing smart contracts with Hardhat is essential before frontend integration and deployment.

7

Deployment to testnets (e.g., Polygon Mumbai) using platforms like Alchemy is a realistic step before mainnet deployment.

UNDERSTANDING NFTS AND COLLECTIONS

An NFT (Non-Fungible Token) is a unique digital asset, often representing artwork, but can also signify domain names or physical items. NFTs are frequently presented in collections, where unique graphics are generated by randomly combining various layers like hair, clothing, and eyes. The rarity of specific traits or attributes adds a layer of artificial scarcity and potential value, similar to opening collectible trading card packs. Smart contracts act as decentralized vending machines, minting a unique token and transferring it to a user's wallet upon payment. Creators can also earn royalties from secondary market sales.

GENERATING NFT ARTWORK AND METADATA

The process begins with creating individual art layers for traits like hair, eyes, and mouths. These layers are digitized and then combined programmatically using tools like Node.js to generate a large number of unique graphics. For each generated image, a JSON metadata file is created. This metadata includes the name of the NFT, a link to its image stored on the Interplanetary File System (IPFS), and attributes detailing the traits and their rarity. This off-chain storage is key, as storing large files directly on the blockchain is inefficient.

STORING ASSETS ON IPFS

The generated artwork and metadata are too large for efficient blockchain storage. The Interplanetary File System (IPFS) provides a decentralized solution for storing these files. When a file is uploaded to IPFS, it receives a unique Content Identifier (CID), ensuring authenticity and immutability. This CID serves as the reference point for the NFT. Services like Pinata offer a user-friendly interface and an SDK for uploading files to IPFS, simplifying the process of making them accessible and linked to your NFTs.

SMART CONTRACT DEVELOPMENT WITH SOLIDITY AND OPENZEPPELIN

Solidity is the primary language for writing smart contracts on the Ethereum blockchain. To streamline development, tools like OpenZeppelin provide pre-built, audited contract templates, such as the ERC-721 standard for NFTs. Key functionalities include minting new tokens, managing ownership, and storing URIs (links to metadata). Customizations are made to allow users to mint NFTs by sending Ether to the contract, while also tracking minted URIs to prevent duplicates and ensuring sufficient payment.

TESTING AND DEPLOYMENT WITH HARDHAT

Hardhat is a development environment that simplifies building, testing, and deploying smart contracts. It provides tools for compiling Solidity code, running local blockchain networks for testing, and executing deployment scripts. Unit tests are crucial for verifying smart contract logic before frontend integration. A local Hardhat node can be set up with fake accounts containing ample test Ether, allowing developers to simulate transactions and test contract functions like `payToMint` and `isContentOwned`.

FRONTEND DEVELOPMENT WITH REACT AND ETHERS.JS

A React frontend application serves as the user interface for interacting with the smart contract. Ethers.js is a JavaScript library that facilitates communication between the user's wallet (like MetaMask) and the blockchain. The application checks for MetaMask installation, retrieves the user's wallet balance, and allows users to initiate NFT minting. This involves connecting to the contract using its ABI and address, calling the `payToMint` function with the appropriate metadata URI and Ether value, and waiting for the transaction confirmation.

DEPLOYMENT TO TESTNETS AND BEYOND

Before deploying to the main Ethereum network, it's recommended to deploy to a testnet like Polygon Mumbai. Platforms like Alchemy provide services to help manage and deploy decentralized applications to various networks. This involves configuring Hardhat with network URLs and private keys. For Polygon, the native token is MATIC, which is used for gas fees. Free test MATIC can be obtained from a faucet. Once deployed to a testnet, the contract address is updated in the frontend code, allowing users to interact with the deployed contract.

Building an NFT Application: Do's and Don'ts

Practical takeaways from this episode

Do This

Digitize hand-drawn layers for NFT artwork.
Use Node.js to script random combinations of layers.
Upload artwork and metadata to IPFS for decentralized storage.
Utilize OpenZeppelin for standard Smart Contract templates (e.g., ERC721).
Write comprehensive tests for your smart contracts using Hardhat.
Use Ethers.js to integrate your frontend with the smart contract.
Check for MetaMask or equivalent wallet availability in the browser.
Deploy contracts to testnets (like Polygon Mumbai) before mainnet.
Use services like Alchemy or Infura for reliable blockchain infrastructure.

Avoid This

Rely on centralized web servers for NFT image hosting.
Forget to implement checks for unique metadata URIs in your smart contract.
Skip smart contract testing; write tests before frontend development.
Assume users will have a Web3 wallet; check for installation.
Deploy directly to mainnet without testing on a testnet.
Use unreliable gateways for accessing IPFS content.

Common Questions

An NFT collection is a set of unique digital assets, often artwork, created by combining different base layers (like hair, eyes, clothing) randomly. Each combination results in a unique NFT, and traits have varying rarity levels, influencing value.

Topics

Mentioned in this video

softwarePinata

A free and easy-to-use service for uploading files to IPFS, supporting programmatic uploads via an SDK.

softwareEthers.js

A JavaScript library for interacting with the Ethereum blockchain and smart contracts from a web application.

conceptPolygon

A blockchain built on top of Ethereum, offering faster and less expensive transactions, used here for testnet deployment.

softwareChainlink

A decentralized oracle network recommended for implementing randomness in smart contracts.

conceptDoodles

An example of an NFT collection.

organizationCodeStacker

Provided a recent tutorial for a more simplified NFT creation approach without coding.

conceptBitTorrent

A peer-to-peer file sharing protocol mentioned as being similar to IPFS.

conceptERC721

A standard interface for non-fungible tokens on the Ethereum blockchain.

softwareMetaMask

A popular browser extension and wallet used by end-users to interact with web3 applications and smart contracts.

supplementMatic

The native token of the Polygon blockchain, analogous to Ether, used for gas fees on the testnet.

conceptNon-Fungible Token (NFT)

A unique digital asset, typically representing artwork, that can be owned and traded; often packaged in collections with varying rarity of traits.

softwareInfura

A platform providing infrastructure for decentralized applications, mentioned alongside Alchemy.

softwareBootstrap

A CSS framework added to the project for styling the frontend application.

softwareAlchemy

A platform providing tools and infrastructure to help build and deploy reliable decentralized applications on blockchain networks.

softwareSharp

A Node.js package used to convert SVG images to PNG files.

conceptSolidity

A programming language used for writing Ethereum smart contracts.

softwareWaffle

A testing framework for Ethereum smart contracts.

softwareRemix IDE

A browser-based IDE for compiling and testing Solidity smart contracts.

softwareSignal

An encrypted messaging app whose creator made an NFT that changes appearance based on where it's viewed.

softwareHardhat

A development environment for Ethereum that provides tools for compiling, testing, and deploying smart contracts.

softwareOpenZeppelin

A widely used library that provides secure, reusable templates for smart contracts, including ERC721 standards.

softwareOpenSea

A secondary market where NFTs can be bought and sold.

conceptBored Ape Yacht Club

An example of an NFT collection.

softwareVite

A build tool used for generating the new React app.

conceptCryptopunks

An example of an NFT collection.

conceptInterPlanetary File System (IPFS)

A decentralized file system used to store NFT image data and JSON metadata off-chain, providing content addressability and immutability.

toolReact
toolGitHub
toolNode.js

More from Fireship

View all 16 summaries

Found this useful? Build your knowledge library

Get AI-powered summaries of any YouTube video, podcast, or article in seconds. Save them to your personal pods and access them anytime.

Try Summify free