Gas Optimization for NFTs Flashcards
6 cards from real NFT practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 6 Gas Optimization for NFTs flashcards as text
Which Layer 2 scaling approach uses validity proofs to batch NFT transactions, offering the strongest security guarantees?
Answer: ZK-Rollups
ZK-Rollups generate a cryptographic validity proof for each batch, allowing immediate finality on L1 without a fraud-proof challenge window.
When generating on-chain SVG NFTs, which approach is more gas-efficient for rendering?
Answer: Storing trait parameters and constructing the SVG string in a `view` function at read time
Storing minimal trait data and assembling SVG in a `view` function costs no gas for reads and far less storage than persisting full SVG strings.
What is the primary gas benefit of using `uint256` for token IDs rather than `uint128` in ERC-721 contracts?
Answer: uint256 fits exactly in one storage slot, avoiding costly masking operations
The EVM operates natively on 32-byte (256-bit) words, so using `uint256` avoids extra masking/shifting instructions needed to read smaller types from packed slots.
How does the `CREATE2` opcode help NFT marketplace contracts reduce gas for predictable addresses?
Answer: It allows pre-computing a contract address before deployment, enabling gas-free counterfactual interactions
CREATE2 derives a deterministic address from salt and bytecode, so parties can interact with (and even send funds to) a contract before it is deployed.
What is the gas cost difference between reading a `constant` variable and reading a regular `storage` variable in Solidity?
Answer: Constants are inlined in bytecode and cost ~3 gas; storage cold reads cost 2100 gas
Constants are substituted directly into bytecode at compile time (no storage slot), so accessing them costs only the stack push (~3 gas) vs. a cold SLOAD at 2100 gas.
Which pattern allows an NFT project to upgrade contract logic without redeploying and migrating token ownership data?
Answer: Using a transparent or UUPS upgradeable proxy pattern
Upgradeable proxies separate storage (proxy) from logic (implementation), allowing the logic contract to be swapped while all token data remains at the original proxy address.