Building an On-Chain NFT with SVG and Smart Contract Deployment
What are NFT’s ?
How does NFT work?
ERC721, widely known as Non-Fungible Tokens (NFTs), are unique digital assets stored on a blockchain that represent ownership or proof of authenticity of a specific item or piece of content. Unlike cryptocurrencies/ERC20 tokens, where each unit is identical and interchangeable, NFTs are one-of-a-kind and cannot be exchanged on a like-for-like basis. This uniqueness is what makes them ideal for representing digital art, artifacts, audio, and other items where provenance, rarity, and originality are crucial. The ERC721 standard on the Ethereum blockchain provides the framework for creating, transferring, and verifying these unique tokens in a secure and decentralized manner.
Key Takeaways
• Ethereum Request for Comment 721 (ERC-721) is the standard for non-fungible tokens created using the Ethereum blockchain.
• ERC-721 provides a framework for creating unique digital assets, ensuring that each token is distinct and not interchangeable.
• NFTs enable verifiable ownership and provenance of digital items such as art, collectibles, and virtual real estate.
• The introduction of NFTs has opened up new markets for digital creativity and asset management on decentralized platforms.
Writing our contact
Creating a Hardhat Project
We will use hardhat to compile and manage our contract. Navigate to a safe directory, and run the following command to initialize a hardhat project initialization wizard:
Before we begin, make sure you have node installed in your computer.
I'm using yarn but you can make use of npm or pnpm. Read more about it in the hardhat documentaion.
yarn add --dev hardhat
npx hardhat init
Creating a smart contract
Now, navigate to the contracts
folder, create a new file named OnchainSVG.sol
. This will be the smart contract file we will work on. Now let's proceed with writing the contract.
Creating the basic structure for a smart contract:
Unlike in the ERC20 article, We are using what is called a library. OpenZeppelin is a platform that provides security solutions for smart contracts and blockchain applications. It offers a library of smart contracts, audits, and tools to help developers build secure applications.
You can read it in the OpenZeppelin Documentation.
We then declared a new contract named OnChainSVG
that inherits from the ERC721 standard contract.
Inheritance allows us to reuse all the NFT logic from ERC721 while adding our custom features.
Defining the state variables
Now, let's define the state variables we will use in the contract