How We Built the Quantum Genesis Smart Contract: A Gas-Optimized ERC-721 with EIP-2981 Royalties on Polygon
Requirements: What We Needed

Quantum Genesis NFT #1 — gerado no Origin Quantum WK_C180

Quantum Genesis NFT #55 — mintado via web3.py no Polygon
For Quantum Genesis, the smart contract had to satisfy non-negotiable constraints:
- 100 NFTs, fixed supply — no minting after deployment
- Batch minting — 10-20 NFTs per transaction to minimize gas
- 5% royalties enforced everywhere — OpenSea, Blur, LooksRare, any EIP-2981 compliant marketplace
- Metadata frozen on-chain — after all 100 uploaded to IPFS, no changes possible
- Zero admin risk — no owner mint, no pause, no upgrade, no token URI changes
- Polygon deployment — cheap enough to mint 100 for under $10
Contract Architecture
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Royalty.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
contract QuantumGenesis is ERC721, ERC721URIStorage, ERC721Royalty, Ownable {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
uint256 public constant MAX_SUPPLY = 100;
bool public _frozen = false;
constructor() ERC721("Quantum Genesis", "QGEN") Ownable(msg.sender) {
_setTokenRoyalty(0, msg.sender, 500); // 5% default (bps)
}
...
Batch Minting: Gas Optimization
Single NFT mint on Ethereum mainnet: ~150,000 gas. On Polygon with our batch function: ~35,000 gas per NFT.
function mintBatch(address[] calldata to, uint256[] calldata tokenIds)
external
onlyOwner
{
require(to.length == tokenIds.length, "Length mismatch");
require(to.length > 0 && to.length <= 20, "Batch 1-20");
for (uint256 i = 0; i < to.length; i++) {
uint256 tokenId = tokenIds[i];
require(tokenId > 0 && tokenId <= MAX_SUPPLY, "Invalid tokenId");
require(_owners(tokenId) == address(0), "Already minted");
_tokenIds.increment();
_safeMint(to[i], tokenId);
}
}
Results: 100 NFTs in 5 transactions of 20. Total gas: ~3.5M units. At 30 gwei MATIC: ~$8.40 total.
EIP-2981 Royalties: Protocol-Level Enforcement
No marketplace opt-in required. The contract implements royaltyInfo from ERC721Royalty:
function royaltyInfo(uint256 tokenId, uint256 salePrice)
external
view
returns (address receiver, uint256 royaltyAmount)
{
require(_exists(tokenId), "Token does not exist");
return (msg.sender, (salePrice * 500) / 10000); // 5% = 500 bps
}
Works on OpenSea, Blur, LooksRare, Magic Eden, any EIP-2981 indexer. No marketplace can bypass it.
Metadata Freezing: Immutable Provenance
After all 100 NFTs are minted and metadata uploaded to IPFS, we call freeze() once:
function setTokenURI(uint256 tokenId, string calldata uri)
external
onlyOwner
{
require(!_frozen, "Contract frozen");
require(_exists(tokenId), "Token does not exist");
_setTokenURI(tokenId, uri);
}
function freeze() external onlyOwner {
_frozen = true;
}
function _setTokenURI(uint256 tokenId, string calldata uri)
internal
override(ERC721, ERC721URIStorage)
{
require(!_frozen, "Contract frozen");
super._setTokenURI(tokenId, uri);
}
After freeze(), no one — not even the owner — can change any tokenURI. The provenance is permanent.
Security: No Admin Keys, No Upgradability
- No proxy pattern — logic and storage in one contract
- No pause function — contract cannot be stopped
- No mint after deployment — only batch mint in constructor window
- Owner can only: withdraw royalties, set initial URIs (before freeze), transfer ownership
- No
setBaseURI— each token has individual URI set at mint
Deployment & Verification on Polygon
- Compile with Hardhat:
npx hardhat compile - Deploy:
npx hardhat run scripts/deploy.ts --network polygon - Verify on PolygonScan:
npx hardhat verify --network polygon CONTRACT_ADDRESS - Call
freeze()after all 100 URIs set - Renounce ownership (optional):
renounceOwnership()
Contract: 0x488fCfaEA5fDf1cF6BAED5e8A34D7858033E1a27
Full Source Code
Complete contract, deployment script, and test suite on GitHub:
Quantum Genesis #1 — the first NFT minted from the custom ERC-721 contract
Quantum Genesis — Contract deployed, verified, frozen. Physics doesn't negotiate.
View on PolygonScan → |
Source Code →
Comentários
Postar um comentário