Deploying ERC-721 NFT
Non-Fungible Tokens (NFTs) are unique digital assets that represent ownership of a specific item or piece of content on the blockchain. The ERC-721 standard defines a common interface for NFTs, ensuring interoperability across platforms and marketplaces.
Within the peaq ecosystem, NFTs can be more than digital collectibles. For example, organizations, innovators, and entrepreneurs building DePINs and dApps on the peaq network could use ERC-721s to:
- Represent and manage the unique identity of connected devices in a Machine Economy (e.g., electric scooters, autonomous drones, or charging stations).
- Facilitate digital identity (DID) whitelist solutions where each person or entity (like a vehicle or machine) is represented as a unique NFT, easing onboarding, access controls, and lifecycle management.
- Tokenize real-world machine-based activities or digital certificates that attest to certain functionalities, ensuring authenticity and traceability within decentralized marketplaces.
Prerequisites
- Basic Blockchain Knowledge: You understand what the Ethereum Virtual Machine (EVM) and smart contracts are and have already deployed an ERC-20 token using Remix IDE before (see tutorial - Deploying ERC-20 Token).
- Access to Remix: You have opened Remix in your browser and are familiar with its basic functionality.
- MetaMask & Test Network: You have MetaMask or another Web3 wallet installed and connected to a test network (like AGUNG) or a local blockchain (e.g., Hardhat or Ganache) for testing.
- Standard ERC-721 Boilerplate: You have a standard ERC-721 contract template (e.g., from OpenZeppelin’s library) ready to customize.
Instructions
1. Obtain an ERC-721 Boilerplate
- Navigate to the OpenZeppelin ERC-721 GitHub repository.
- Copy or import this simple ERC-721 implementation (or a minimal example from the OpenZeppelin docs like
ERC721PresetMinterPauserAutoId.sol
).
2. Create a New File in Remix
- In Remix, click on the File explorer icon (the first icon on the left) and create a new file named, for example,
MyFirstNFT.sol
. - Paste the boilerplate ERC-721 code into the file.
3. Fill in Relevant Details
Within the constructor and contract parameters, you can set:
- Contract Name & Symbol: Choose a name that represents your NFT collection (e.g.,
MyFirstNFT
) and a symbol (e.g.,MFN
). - Base URI: If your contract includes a base URI, set it to a URL pointing to your NFT metadata storage location (e.g.,
https://my-nft-metadata-api.com/metadata/
). IPFS storage systems like Pinata can help store this metadata off-chain to be upgraded later if needed.
Example Constructor Initialization:
4. Compile the Contract
- Click on the Solidity Compiler icon (usually the second icon on the left).
- Select the Solidity version that matches the pragma in your code.
- Click the Compile MyFirstNFT.sol button. Ensure there are no compilation errors.
5. Deploy the Contract
- Click on the Deploy & Run Transactions icon (usually the third icon on the left).
- In the Environment dropdown, select your desired network (e.g.,
Injected Web3
to use Metamask’s currently selected network). - Click on the Deploy button.
- Confirm the transaction in Metamask. Once the transaction is mined, your contract address will appear in Remix’s deployed contracts section.
6. Minting and Interacting
- Use the contract’s
mint
function (if included) or any custom function to create a new NFT. - After minting, you can view the token details (e.g.,
ownerOf(tokenId)
,tokenURI(tokenId)
) directly in Remix or using block explorers.
7. Testing & Next Steps
- Verify your contract on a test network like AGUNG and ensure your NFT appears on NFT-supporting platforms or on block explorers like Subscan (AGUNG) / Subscan (PEAQ) .
- Once confident, you can migrate to mainnet or integrate with the peaq ecosystem’s unique functionalities—such as representing machine IDs or tokenizing machine-based services—and leverage peaq’s infrastructure for future improvements, liquidity, and interoperability.
Summary
By following these steps, you’ve successfully deployed a ERC-721 NFT contract. Over time, you can refine the contract, incorporate advanced features (like access control, royalties, or custom metadata handling, unique mint/burn functions, etc. ), and build rich applications that harness the potential of NFTs in the peaq ecosystem’s machine-centric marketplace.