Unit 5: Solidity - Practice Quiz
1 What is Remix IDE primarily used for?
2 How can the Remix IDE be accessed most easily?
3 Which file extension is used for Solidity source files in Remix?
4 In Remix, which panel is used to compile a smart contract?
5 What type of token does the ERC-20 standard define?
6 What type of token does the ERC-721 standard define?
7 Which ERC-20 function returns the total number of tokens in existence?
transfer()
totalSupply()
balanceOf()
approve()
8 Which standard is most commonly used to represent digital collectibles like unique artwork?
9 What does the "ERC" in ERC-20 stand for?
10 Which keyword is used to declare a smart contract in Solidity?
class
struct
contract
module
11 Which statement specifies the Solidity compiler version at the top of a file?
use solidity
pragma solidity
version solidity
import solidity
12 Which data type is used to store true/false values in Solidity?
int
address
string
bool
13 Which Solidity type is specifically used to hold an Ethereum account address?
address
mapping
uint
bytes
14 What is the default function visibility recommendation for a function meant to be called from outside the contract?
hidden
private
internal
public
15 Which keyword is used to define a function in Solidity?
method
def
function
func
16 What does "deploying" a smart contract mean?
17 Once deployed to the blockchain, smart contract code is generally:
18 What is typically required to execute a state-changing transaction on a smart contract?
19 Which JavaScript library is commonly used to connect a web user interface to Ethereum smart contracts?
20 Which browser tool is commonly used to let users sign transactions from a dApp interface?
21 A developer opens Remix IDE in a browser but cannot see the Deploy & Run Transactions panel. Which action most directly restores access to deployment functionality?
22 In Remix, a student wants to test a contract without spending real Ether or waiting for block confirmations. Which environment under Deploy & Run should they select?
23 A contract compiles successfully in Remix, but the developer wants it to always compile when the file is saved. Which compiler setting achieves this?
24
Consider the declaration mapping(address => uint256) public balances;. What does marking it public automatically generate?
25
Which statement about the view and pure function modifiers in Solidity is correct?
view function may modify state, while a pure function only reads state
view and pure functions can modify state variables
pure function can read state but a view function cannot
pure function may neither read nor modify state, while a view function may read but not modify state
26
A developer writes require(msg.sender == owner, "Not owner"); at the start of a function. What happens if the condition is false?
27
What is the primary reason to use calldata instead of memory for a function parameter in an external function?
calldata stores the data permanently on-chain
calldata is required for all internal function parameters
calldata is read-only and avoids a copy, reducing gas costs
calldata allows the parameter to be modified in place
28
Given uint8 x = 255; x = x + 1; in a Solidity 0.8.x contract, what is the result?
x becomes 256
x silently wraps around to 0
29
Which combination correctly describes when a Solidity function must be marked payable?
msg.value
internal
uint256 value
30 Which function signature belongs to the ERC-20 standard but has no equivalent in ERC-721?
ownerOf(uint256 tokenId) returns (address)
totalSupply() returns (uint256) representing fungible token count
tokenURI(uint256 tokenId) returns (string)
safeTransferFrom(address, address, uint256) with token metadata
31
In ERC-20, why does a user typically call approve(spender, amount) before a decentralized exchange can move their tokens?
amount for the spender
amount tokens on the user's behalf
32 An ERC-721 token represents a unique digital artwork. Which mechanism links the token to its off-chain image and metadata?
totalSupply function storing the image hash
decimals function returning the image resolution
allowance mapping holding the file path
tokenURI function returning a URI to a JSON metadata file
33
An ERC-20 token sets decimals() to 18 and a user wants to send 5 whole tokens. What integer value should be passed to transfer?
34
Why is safeTransferFrom preferred over transferFrom when sending an ERC-721 token to a contract address?
onERC721Received, preventing tokens from being locked
35 A deployed contract has a bug, but its code is immutable. Which design pattern allows the logic to be upgraded while keeping the same contract address and storage?
pure to avoid bugs
selfdestruct after every transaction
36 Which practice best restricts a sensitive administrative function so that only the deployer can call it?
pure
public and view
onlyOwner modifier that checks msg.sender == owner
37 A developer wants to notify an off-chain application whenever a transfer occurs, in a gas-efficient and queryable way. What should the contract use?
public string every transfer
event with indexed parameters for logging
38 After deploying a contract in Remix, a developer wants to interact with the same contract later from a script. Which two pieces of information are essential?
39 A web front end built with ethers.js needs the user to approve a token transfer transaction. Which component typically prompts the user to sign and send it?
40 In a DApp front end, why is the contract ABI required to call a smart contract function from JavaScript?
41
A developer compiles a contract in Remix using compiler version 0.8.19 but deploys to a testnet where the verification service expects bytecode from 0.8.17. The deployed bytecode fails source verification despite identical source code. What is the most likely root cause?
0.8.0
42 In Remix, you select the 'Injected Provider - MetaMask' environment to deploy a contract. The transaction is sent but never confirmed, and Remix shows the account balance as unchanged. Which explanation is most consistent with this behavior?
43
Consider the classic ERC-20 approve/transferFrom race condition. A spender currently has an allowance of 100. The owner wants to change it to 50. Why is calling approve(spender, 50) directly considered unsafe?
100 and the new 50, totaling 150
approve reverts if the new value is lower than the current one
50
44
An ERC-721 contract implements safeTransferFrom. When transferring a token to a smart contract recipient, which condition must hold to prevent the token from being permanently locked?
tokenURI must be set before transfer
approve on the recipient
onERC721Received returning the correct selector
45
A token claims ERC-20 compliance but its transfer function returns no boolean value (it has no return). Why does this break composability with some protocols?
bool return and may revert or misread the stack when none is provided
46
Given the following, what does f() return?
solidity
function f() public pure returns (uint) {
uint8 a = 255;
unchecked { a += 1; }
return a;
}
255
0
256
47
Which statement about delegatecall is correct regarding storage and context?
delegatecall always resets msg.sender to the callee address
delegatecall cannot modify any state variables
msg.sender, and msg.value context
48
A contract has a receive() function and a fallback() function. A transaction sends ETH with empty calldata. Which function executes?
receive() executes because calldata is empty and ETH is sent
fallback() executes because ETH was attached
49
What is the key reentrancy risk in this withdraw pattern?
solidity
function withdraw() public {
uint bal = balances[msg.sender];
(bool ok,) = msg.sender.call{value: bal}("");
require(ok);
balances[msg.sender] = 0;
}
call cannot transfer ETH, so withdrawals silently fail
0 first would cause an underflow
bal is read before the call
50
For a dynamically-sized uint256[] stored at slot p, where is element at index i located in storage?
keccak256(p) + i, while slot p holds the array length
keccak256(p + i) for each element independently
p + i, with no separate length slot
p, packed with the length
51 Which modifier combination minimizes gas when a function only reads state and takes no arguments that affect storage?
payable to allow optional ETH
pure even though it reads state variables
view so the function reads state without a state-changing transaction when called externally
virtual to reduce bytecode size
52
What does abi.encodePacked risk when used as input to keccak256 for building a key from two dynamic values?
abi.encode with no benefit
("a","bc") and ("ab","c") encode identically
53
In Solidity 0.8+, which arithmetic operation still reverts even outside an unchecked block only due to a specific invalid operand, not overflow?
uint256 values
54
A proxy-based upgradeable contract uses delegatecall to a logic contract. After an upgrade, previously stored values appear corrupted. What is the most likely cause?
delegatecall erases all storage on upgrade
55
Why do upgradeable contracts use an initialize() function with an initializer guard instead of a constructor?
initialize call via the proxy is required
initialize is cheaper gas than a constructor
56
A contract exposes selfdestruct(owner). What important consequence should management consider about addresses that previously held references to it?
57
When using OpenZeppelin's Ownable with a two-step ownership transfer (Ownable2Step), what risk does it specifically mitigate compared to single-step transfer?
58 A gas-sensitive contract emits events to log state changes instead of storing full history on-chain. What is the correct understanding of this design?
view functions
59
A dApp front-end uses ethers.js to call a view function and a state-changing function. Which pairing of provider/signer usage is correct?
provider for the view call and a signer for the state-changing transaction
signer for both, since providers cannot read state
provider for both, since signers cannot send transactions
60 A front-end listens for a contract event to update the UI after a transaction. Users report the UI sometimes updates then reverts the displayed change. What is the most likely cause?
view functions cannot emit events
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →