CCE Smart Contracts and Ethereum 2 — Questions and Answers
Question 1: What does the ERC-20 token standard define?
- Rules for creating unique non-fungible tokens on Ethereum
- A common set of rules for creating interchangeable (fungible) tokens on Ethereum (Correct answer)
- The protocol governing how Ethereum nodes reach consensus
- Standards for creating multi-signature wallet contracts on Ethereum
Correct answer: A common set of rules for creating interchangeable (fungible) tokens on Ethereum
ERC-20 is a technical standard that defines a common interface for fungible tokens on Ethereum, enabling any compliant token to be used interchangeably across wallets and exchanges.
Question 2: What is the key difference between an Externally Owned Account (EOA) and a contract account in Ethereum?
- EOAs have larger on-chain storage capacity than contract accounts
- Contract accounts are controlled by a private key; EOAs are controlled by code
- EOAs are controlled by a private key; contract accounts are controlled by smart contract code (Correct answer)
- There is no functional difference — both types can be used interchangeably
Correct answer: EOAs are controlled by a private key; contract accounts are controlled by smart contract code
EOAs are controlled by private keys held by users and can initiate transactions, while contract accounts are controlled by their deployed smart contract code and can only respond to incoming transactions.
Question 3: What is a 'reentrancy attack' in the context of smart contracts?
- Repeatedly broadcasting the same signed transaction to drain gas fees
- An attack where a malicious contract calls back into the victim contract before the first execution completes (Correct answer)
- A method to bypass access control by re-registering a contract at a previously used address
- An exploit that prevents a smart contract from ever being called again
Correct answer: An attack where a malicious contract calls back into the victim contract before the first execution completes
A reentrancy attack occurs when a malicious contract recursively calls back into the vulnerable contract before the first call's state updates are finalized, allowing funds to be withdrawn multiple times.
Question 4: What does the 'payable' keyword do in a Solidity smart contract?
- It makes the function free to call by waiving the gas requirement
- It allows a function or address to receive Ether as part of a transaction (Correct answer)
- It automatically sends Ether to the contract owner after every call
- It restricts a function so only verified payment processors can call it
Correct answer: It allows a function or address to receive Ether as part of a transaction
The 'payable' modifier in Solidity allows a function or address to receive Ether; any Ether sent to a non-payable function will cause the transaction to revert.
Question 5: What is the primary purpose of events in Ethereum smart contracts?
- To trigger external API calls from within the blockchain
- To log information to the blockchain that off-chain applications can listen to and act upon (Correct answer)
- To schedule timed future executions of contract functions
- To enable direct communication and data sharing between two smart contracts
Correct answer: To log information to the blockchain that off-chain applications can listen to and act upon
Events emit logs stored on the blockchain that are not accessible by other contracts but can be efficiently monitored by off-chain applications such as DApp frontends or indexing services.
Question 6: What is the ERC-721 standard primarily designed for?
- Creating fungible tokens with a fixed maximum supply cap
- Creating non-fungible tokens (NFTs) where each token has a unique identity (Correct answer)
- Enabling a single contract to manage multiple different token types simultaneously
- Defining how decentralized exchanges should route token swap orders
Correct answer: Creating non-fungible tokens (NFTs) where each token has a unique identity
ERC-721 is the standard for non-fungible tokens on Ethereum, where each token has a unique token ID and is not interchangeable with any other token, making it suitable for digital collectibles and art.
Question 7: What happens when a smart contract transaction runs out of gas during execution?
- The transaction partially completes and saves whatever state changes occurred
- The Ethereum network automatically supplements the needed gas from a reserve pool
- The transaction reverts, all state changes are rolled back, and the gas consumed is not refunded (Correct answer)
- The smart contract is permanently disabled and removed from the blockchain
Correct answer: The transaction reverts, all state changes are rolled back, and the gas consumed is not refunded
When gas runs out, execution halts, all state changes from that transaction are rolled back as if the call never happened, but the gas already consumed is forfeited and not refunded to the sender.
What does the ERC-20 token standard define?