Unit 5: Solidity - Practice Quiz

CSC307 — Blockchain Architecture And Design-I 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What is Remix IDE primarily used for?

installing Remix IDE (online Solidity compiler and development environment) Easy
A. Writing, compiling, and deploying Solidity smart contracts
B. Editing image files
C. Managing cloud storage buckets
D. Designing website frontends

2 How can the Remix IDE be accessed most easily?

installing Remix IDE (online Solidity compiler and development environment) Easy
A. Through a web browser online
B. Only by installing a desktop OS
C. Only via a hardware wallet
D. Only through a mobile SMS app

3 Which file extension is used for Solidity source files in Remix?

installing Remix IDE (online Solidity compiler and development environment) Easy
A. .sol
B. .js
C. .html
D. .py

4 In Remix, which panel is used to compile a smart contract?

installing Remix IDE (online Solidity compiler and development environment) Easy
A. The Terminal panel
B. The Solidity Compiler panel
C. The File Explorer panel
D. The Settings panel

5 What type of token does the ERC-20 standard define?

introduction to token standards (ERC-20, ERC-721) Easy
A. Non-fungible tokens
B. Physical paper tokens
C. Encrypted email tokens
D. Fungible tokens

6 What type of token does the ERC-721 standard define?

introduction to token standards (ERC-20, ERC-721) Easy
A. Fungible tokens
B. Mining rewards only
C. Non-fungible tokens
D. Divisible stablecoins

7 Which ERC-20 function returns the total number of tokens in existence?

introduction to token standards (ERC-20, ERC-721) Easy
A. transfer()
B. totalSupply()
C. balanceOf()
D. approve()

8 Which standard is most commonly used to represent digital collectibles like unique artwork?

introduction to token standards (ERC-20, ERC-721) Easy
A. ERC-20
B. ERC-10
C. ERC-137
D. ERC-721

9 What does the "ERC" in ERC-20 stand for?

introduction to token standards (ERC-20, ERC-721) Easy
A. External Relay Contract
B. Ethereum Resource Code
C. Ethereum Request for Comments
D. Encrypted Record Chain

10 Which keyword is used to declare a smart contract in Solidity?

Solidity programming Easy
A. class
B. struct
C. contract
D. module

11 Which statement specifies the Solidity compiler version at the top of a file?

Solidity programming Easy
A. use solidity
B. pragma solidity
C. version solidity
D. import solidity

12 Which data type is used to store true/false values in Solidity?

Solidity programming Easy
A. int
B. address
C. string
D. bool

13 Which Solidity type is specifically used to hold an Ethereum account address?

Solidity programming Easy
A. address
B. mapping
C. uint
D. bytes

14 What is the default function visibility recommendation for a function meant to be called from outside the contract?

Solidity programming Easy
A. hidden
B. private
C. internal
D. public

15 Which keyword is used to define a function in Solidity?

Solidity programming Easy
A. method
B. def
C. function
D. func

16 What does "deploying" a smart contract mean?

Smart contract management Easy
A. Publishing the contract onto the blockchain
B. Deleting the contract code
C. Printing the contract to paper
D. Compiling the contract only

17 Once deployed to the blockchain, smart contract code is generally:

Smart contract management Easy
A. Automatically deleted daily
B. Immutable (cannot be changed)
C. Editable at any time
D. Stored only on the user's device

18 What is typically required to execute a state-changing transaction on a smart contract?

Smart contract management Easy
A. Gas fees
B. An email confirmation
C. A phone number
D. A printed receipt

19 Which JavaScript library is commonly used to connect a web user interface to Ethereum smart contracts?

User Interface Easy
A. Bootstrap.io
B. NodePaint
C. jQuery.css
D. Web3.js

20 Which browser tool is commonly used to let users sign transactions from a dApp interface?

User Interface Easy
A. A spreadsheet app
B. MetaMask wallet
C. A calculator app
D. Microsoft Word

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?

installing Remix IDE (online Solidity compiler and development environment) Medium
A. Switching the Solidity compiler to a lower version
B. Activating the Deploy & Run Transactions plugin from the Plugin Manager
C. Reinstalling the browser to refresh cached files
D. Clearing all files from the default workspace

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?

installing Remix IDE (online Solidity compiler and development environment) Medium
A. Remix VM (in-browser simulated blockchain)
B. External HTTP provider pointing to a public node
C. Injected Provider - MetaMask on mainnet
D. WalletConnect to a hardware wallet

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?

installing Remix IDE (online Solidity compiler and development environment) Medium
A. Lowering the optimizer runs value to 1
B. Enabling Auto compile in the Solidity Compiler tab
C. Turning off the hardcoded compiler version
D. Enabling the SMTChecker module

24 Consider the declaration mapping(address => uint256) public balances;. What does marking it public automatically generate?

Solidity programming Medium
A. An event emitted whenever the mapping changes
B. A getter function that takes an address and returns its balance
C. A constructor that initializes all balances to zero
D. A setter function to update any address balance

25 Which statement about the view and pure function modifiers in Solidity is correct?

Solidity programming Medium
A. A view function may modify state, while a pure function only reads state
B. Both view and pure functions can modify state variables
C. A pure function can read state but a view function cannot
D. A 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?

Solidity programming Medium
A. All remaining gas is consumed and no message is returned
B. The transaction reverts, state changes are undone, and remaining gas is refunded
C. The function silently returns a default value
D. The condition is logged but execution continues

27 What is the primary reason to use calldata instead of memory for a function parameter in an external function?

Solidity programming Medium
A. calldata stores the data permanently on-chain
B. calldata is required for all internal function parameters
C. calldata is read-only and avoids a copy, reducing gas costs
D. 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?

Solidity programming Medium
A. x becomes 256
B. x silently wraps around to 0
C. The contract fails to compile
D. The transaction reverts due to an overflow check

29 Which combination correctly describes when a Solidity function must be marked payable?

Solidity programming Medium
A. When the function is intended to receive Ether via msg.value
B. When the function is declared as internal
C. When the function returns a uint256 value
D. When the function only reads state variables

30 Which function signature belongs to the ERC-20 standard but has no equivalent in ERC-721?

introduction to token standards (ERC-20, ERC-721) Medium
A. ownerOf(uint256 tokenId) returns (address)
B. totalSupply() returns (uint256) representing fungible token count
C. tokenURI(uint256 tokenId) returns (string)
D. 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?

introduction to token standards (ERC-20, ERC-721) Medium
A. It mints new tokens equal to amount for the spender
B. It burns the approved amount from the user's balance
C. It permanently transfers ownership of all tokens to the spender
D. It authorizes the spender to transfer up to 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?

introduction to token standards (ERC-20, ERC-721) Medium
A. The totalSupply function storing the image hash
B. The decimals function returning the image resolution
C. The allowance mapping holding the file path
D. The 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?

introduction to token standards (ERC-20, ERC-721) Medium
A.
B.
C.
D.

34 Why is safeTransferFrom preferred over transferFrom when sending an ERC-721 token to a contract address?

introduction to token standards (ERC-20, ERC-721) Medium
A. It automatically mints a replacement token for the sender
B. It checks that the receiving contract implements onERC721Received, preventing tokens from being locked
C. It bypasses ownership verification for contract recipients
D. It transfers the token twice as fast using less gas

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?

Smart contract management Medium
A. Hardcoding all functions as pure to avoid bugs
B. Using selfdestruct after every transaction
C. Redeploying the contract to a new address each time
D. The proxy pattern delegating calls to a replaceable logic contract

36 Which practice best restricts a sensitive administrative function so that only the deployer can call it?

Smart contract management Medium
A. Emitting an event before the function body
B. Declaring the function as pure
C. Marking the function as public and view
D. Using an 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?

Smart contract management Medium
A. Return the transfer details from the function
B. Store each transfer in a growing array of structs
C. Write the data to a public string every transfer
D. Emit an 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?

Smart contract management Medium
A. The function names and the chain ID only
B. The contract address and its ABI
C. The private key and the block number
D. The compiler version and the gas price

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?

User Interface Medium
A. The block explorer displaying the transaction
B. The Solidity compiler running in the browser
C. The contract ABI stored in local storage
D. A browser wallet such as MetaMask acting as the injected provider

40 In a DApp front end, why is the contract ABI required to call a smart contract function from JavaScript?

User Interface Medium
A. It defines how to encode function calls and decode return data
B. It holds the current gas price for the network
C. It stores the user's private key for signing
D. It contains the compiled bytecode deployed on-chain

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?

installing Remix IDE (online Solidity compiler and development environment) Hard
A. Remix always strips the metadata hash, so verification is impossible
B. Source verification only works with the Hardhat plugin, never Remix
C. The compiler version and optimization settings embedded in the metadata hash differ, producing different bytecode
D. The testnet does not support any contract above version 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?

installing Remix IDE (online Solidity compiler and development environment) Hard
A. Injected Provider cannot deploy contracts, only call view functions
B. MetaMask is connected to a different network than the one your contract targets, so the tx sits in a mismatched mempool or is dropped
C. Remix's JavaScript VM overrides MetaMask during deployment
D. The contract must be flattened before any injected deployment

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?

introduction to token standards (ERC-20, ERC-721) Hard
A. The spender can front-run the new approval and spend both the old 100 and the new 50, totaling 150
B. approve reverts if the new value is lower than the current one
C. ERC-20 forbids reducing an allowance once set
D. The allowance resets to zero automatically, losing the 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?

introduction to token standards (ERC-20, ERC-721) Hard
A. The token's tokenURI must be set before transfer
B. The sender must first call approve on the recipient
C. The recipient must hold a positive ETH balance
D. The recipient contract must implement 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?

introduction to token standards (ERC-20, ERC-721) Hard
A. Solidity refuses to compile such a function
B. Protocols using the standard interface expect a bool return and may revert or misread the stack when none is provided
C. The token's total supply becomes undefined
D. The EVM cannot execute functions without return values

46 Given the following, what does f() return?

solidity
function f() public pure returns (uint) {
uint8 a = 255;
unchecked { a += 1; }
return a;
}

Solidity programming Hard
A. 255
B. 0
C. 256
D. The call reverts with an overflow panic

47 Which statement about delegatecall is correct regarding storage and context?

Solidity programming Hard
A. delegatecall always resets msg.sender to the callee address
B. delegatecall cannot modify any state variables
C. Code of the callee executes in the caller's storage, msg.sender, and msg.value context
D. Code of the callee executes in the callee's own storage context

48 A contract has a receive() function and a fallback() function. A transaction sends ETH with empty calldata. Which function executes?

Solidity programming Hard
A. receive() executes because calldata is empty and ETH is sent
B. Both execute in sequence
C. fallback() executes because ETH was attached
D. Neither executes; the transaction reverts

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;
}

Solidity programming Hard
A. State is updated after the external call, letting a malicious receiver re-enter and drain funds
B. call cannot transfer ETH, so withdrawals silently fail
C. Setting the balance to 0 first would cause an underflow
D. The function reverts because 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?

Solidity programming Hard
A. At keccak256(p) + i, while slot p holds the array length
B. At keccak256(p + i) for each element independently
C. At slot p + i, with no separate length slot
D. At 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?

Solidity programming Hard
A. payable to allow optional ETH
B. pure even though it reads state variables
C. view so the function reads state without a state-changing transaction when called externally
D. 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?

Solidity programming Hard
A. It doubles gas versus abi.encode with no benefit
B. It automatically truncates strings to 32 bytes
C. It always reverts on dynamic types
D. Hash collisions, because packing removes padding so ("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?

Solidity programming Hard
A. Subtraction yielding a positive result
B. Addition of two large uint256 values
C. Division or modulo by zero
D. Multiplication within type range

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?

Smart contract management Hard
A. delegatecall erases all storage on upgrade
B. The new logic contract's storage layout does not match the old one, so variables map to different slots
C. The proxy address changed during the upgrade
D. Constructors ran again and reset the values

55 Why do upgradeable contracts use an initialize() function with an initializer guard instead of a constructor?

Smart contract management Hard
A. Constructor code runs in the logic contract's own context and never affects the proxy's storage, so an initialize call via the proxy is required
B. Constructors cannot set state variables
C. Constructors are banned in Solidity 0.8+
D. 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?

Smart contract management Hard
A. External contracts automatically update their stored address
B. All tokens it held are automatically burned on-chain forever
C. The contract's code regenerates on the next call
D. Calls to the destroyed contract succeed as no-ops to an EOA-like empty account, so dependent logic may silently misbehave

57 When using OpenZeppelin's Ownable with a two-step ownership transfer (Ownable2Step), what risk does it specifically mitigate compared to single-step transfer?

Smart contract management Hard
A. It encrypts the owner address on-chain
B. It allows multiple owners simultaneously
C. It makes ownership transfers free of gas
D. It prevents permanently losing control by transferring to a wrong or inaccessible address, since the new owner must accept

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?

Smart contract management Hard
A. Events can be queried by other contracts to reconstruct state
B. Events are cheaper than storage but still readable via view functions
C. Events are stored in logs that contracts cannot read, so they are for off-chain consumers, not on-chain logic
D. Events permanently replace the need for any storage variables

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?

User Interface Hard
A. Use a provider for the view call and a signer for the state-changing transaction
B. Use a signer for both, since providers cannot read state
C. Use neither; call contracts directly over HTTP
D. Use a 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?

User Interface Hard
A. Events are not supported by ethers.js listeners
B. The event fired on a block that was later reorganized out of the canonical chain
C. The ABI is missing the event definition
D. view functions cannot emit events