NFT Gas Optimization for NFTs 1 — Questions and Answers
Question 1: Which ERC standard is more gas-efficient when minting large quantities of fungible or semi-fungible tokens?
- ERC-20
- ERC-721
- ERC-1155 (Correct answer)
- ERC-777
Correct answer: ERC-1155
ERC-1155 allows batch minting of multiple token types in a single transaction, significantly reducing per-token gas costs compared to ERC-721.
Question 2: What is 'lazy minting' in NFT development?
- Minting tokens without any metadata
- Deferring on-chain minting until the first purchase or claim (Correct answer)
- Minting tokens on a testnet before mainnet
- Pre-minting all tokens at contract deployment
Correct answer: Deferring on-chain minting until the first purchase or claim
Lazy minting defers the actual on-chain transaction until a buyer claims the NFT, so the creator avoids upfront gas costs.
Question 3: Which storage approach costs the least gas for associating large data with an NFT?
- Storing the full data in a contract mapping
- Storing the full data in a contract array
- Emitting the data as an event log
- Storing only a content-addressed URI pointing to off-chain storage (Correct answer)
Correct answer: Storing only a content-addressed URI pointing to off-chain storage
Storing only a URI (e.g., pointing to IPFS) on-chain is far cheaper than storing raw data in contract storage slots.
Question 4: What does the ERC-721A standard optimize compared to standard ERC-721?
- Reducing the size of NFT images
- Lowering gas costs for batch minting sequential token IDs (Correct answer)
- Enabling cross-chain NFT transfers
- Adding built-in royalty enforcement
Correct answer: Lowering gas costs for batch minting sequential token IDs
ERC-721A by Azuki writes batch ownership data once instead of per-token, dramatically cutting gas for minting multiple tokens in one transaction.
Question 5: Which Solidity technique reduces gas costs by skipping overflow/underflow checks for a counter known to be safe?
- using SafeMath
- using unchecked {} blocks (Correct answer)
- using assembly
- using immutable variables
Correct answer: using unchecked {} blocks
Wrapping arithmetic in `unchecked {}` skips Solidity 0.8's built-in overflow checks, saving gas when the developer can guarantee no overflow.
Question 6: Why is packing multiple small variables into a single storage slot beneficial in NFT contracts?
- It increases readability
- It reduces the number of SSTORE operations, lowering gas costs (Correct answer)
- It allows storing more metadata on-chain
- It speeds up off-chain indexing
Correct answer: It reduces the number of SSTORE operations, lowering gas costs
Each Ethereum storage slot is 32 bytes; packing variables like `uint128` together means fewer slots are written, reducing expensive SSTORE costs.
Which ERC standard is more gas-efficient when minting large quantities of fungible or semi-fungible tokens?