Blockchain Developer FREE Blockchain Developer Smart Contract Development Questions and Answers 2 — Questions and Answers
Question 1: What is the primary purpose of the 'require' statement in Solidity smart contracts?
- To validate conditions and revert the transaction if not met (Correct answer)
- To import external libraries
- To declare state variables
- To define function visibility
Correct answer: To validate conditions and revert the transaction if not met
The 'require' statement checks a condition and reverts the entire transaction with remaining gas refunded if the condition evaluates to false.
Question 2: Which design pattern is used to allow upgrading smart contract logic while preserving stored data?
- Proxy pattern (Correct answer)
- Factory pattern
- Observer pattern
- Singleton pattern
Correct answer: Proxy pattern
The proxy pattern delegates calls to an implementation contract, allowing the logic to be swapped while the proxy retains all state and the same address.
Question 3: What happens when a smart contract function marked as 'view' attempts to modify state?
- The compiler throws an error (Correct answer)
- The modification is silently ignored
- The transaction reverts at runtime
- The function executes normally
Correct answer: The compiler throws an error
The Solidity compiler enforces that 'view' functions cannot modify state and will produce a compilation error if state modification is attempted.
Question 4: In Solidity, what is the maximum size of a deployed smart contract's bytecode on Ethereum mainnet?
- 24,576 bytes (Correct answer)
- 16,384 bytes
- 32,768 bytes
- 49,152 bytes
Correct answer: 24,576 bytes
EIP-170 introduced a contract size limit of 24,576 bytes (24 KB) to prevent denial-of-service attacks on the network.
Question 5: Which vulnerability occurs when a contract makes an external call before updating its own state?
- Reentrancy attack (Correct answer)
- Integer overflow
- Front-running
- Access control bypass
Correct answer: Reentrancy attack
Reentrancy occurs when an external call allows the called contract to re-enter the calling function before state updates are completed.
Question 6: What is the purpose of the 'indexed' keyword for event parameters in Solidity?
- It allows the parameter to be used as a filter when searching logs (Correct answer)
- It stores the parameter in contract storage
- It makes the parameter immutable
- It encrypts the parameter value
Correct answer: It allows the parameter to be used as a filter when searching logs
Indexed event parameters are stored as topics in the transaction log, enabling efficient filtering and searching of events by those values.
What is the primary purpose of the 'require' statement in Solidity smart contracts?