Prepare for your Solidity developer interview with these 30 essential questions covering basic, intermediate, and advanced concepts. This guide progresses from foundational topics to complex scenarios, helping freshers, 1-3 year experienced, and 3-6 year professionals master Solidity smart contract development.
Basic Solidity Interview Questions (1-10)
1. What is Solidity?
Solidity is a statically-typed, high-level object-oriented programming language designed for developing smart contracts that run on the Ethereum Virtual Machine (EVM).[5]
2. What are the main components of a Solidity smart contract?
The main components include pragma statement, state variables, constructor, functions, modifiers, events, and inheritance support for code reuse.[3][5]
3. Explain the difference between storage and memory variables in Solidity.
Storage variables are persistent on the blockchain and expensive in gas, while memory variables are temporary and exist only during function execution.[1]
4. What are the visibility modifiers in Solidity functions?
Visibility modifiers are public, private, internal, and external. Public functions are callable externally and internally, private only internally by the contract, internal by contract and derived contracts, external only externally.[2]
5. What is a pragma statement in Solidity?
The pragma statement specifies the Solidity compiler version required, like pragma solidity ^0.8.0; to ensure compatibility.[3]
6. Differentiate between view and pure functions.
View functions read state but don’t modify it, while pure functions neither read nor modify state and can’t access storage.[3]
7. What is a constructor in Solidity?
A constructor is a special function executed once during contract deployment to initialize state variables.[3][5]
8. How do you define state variables in Solidity?
State variables store persistent data on the blockchain, declared at contract level like uint public balance;.[5]
9. What are events in Solidity?
Events create logs for external applications to track contract activity, declared as event Transfer(address from, address to, uint amount);.[3]
10. Explain mappings in Solidity.
Mappings store key-value pairs like mapping(address => uint) public balances;, where keys map to values with default zero initialization.[5]
Intermediate Solidity Interview Questions (11-20)
11. What is function overriding in Solidity inheritance?
Child contracts can override parent virtual functions using the override keyword to extend or modify inherited behavior.[5]
12. How does the Solidity compiler work?
The Solidity compiler (solc) translates human-readable code into EVM bytecode and ABI for deployment and interaction.[1][3]
13. What are modifiers in Solidity?
Modifiers are reusable code blocks added to functions for checks, like access control: modifier onlyOwner() { require(msg.sender == owner); _; }.[3]
14. Explain require, assert, and revert statements.
require validates inputs and refunds gas, assert checks invariants (no refund), revert undoes state changes with custom error.[1]
15. What is msg.sender in Solidity?
msg.sender represents the address calling the function, crucial for access control and authorization.[6]
16. How do you handle errors in Solidity 0.8.0+?
Solidity 0.8.0 introduced safe arithmetic with overflow checks and custom errors for gas-efficient reverts like error InsufficientBalance(uint requested, uint available);.[2]
17. What is the difference between create and create2 opcodes?
create deploys contracts with unpredictable addresses, while create2 allows predictable addresses using salt for deterministic deployment.[2]
18. Scenario: At Zoho, how would you implement a simple voting contract?
Create a contract with mapping(address => bool) voted; and mapping(uint => uint) votes;, using modifier to prevent double voting.[1]
19. What keywords measure time in Solidity?
block.timestamp, block.number, and now (alias for timestamp) measure time for timeouts and scheduling.[2]
20. Explain gas optimization for loops in Solidity.
Limit loop iterations with constants, use unchecked for safe math in 0.8.0+, and prefer mappings over arrays for lookups.[4]
Advanced Solidity Interview Questions (21-30)
21. What changed with arithmetic in Solidity 0.8.0?
Solidity 0.8.0 enabled built-in overflow/underflow checks for safer arithmetic; use unchecked blocks to bypass for gas savings.[2]
22. Scenario: At Salesforce, prevent reentrancy in a withdrawal function.
Use checks-effects-interactions pattern: validate, update state, then transfer Ether to avoid recursive calls.[6]
23. What is delegatecall and its risks?
delegatecall executes code in the caller’s storage context, used in proxies but risks storage corruption if layouts mismatch.[2]
24. How large can a smart contract be approximately?
Smart contracts are limited to ~24KB due to EVM gas constraints for deployment and execution.[2]
25. What operations provide partial gas refunds?
Deleting mappings/arrays (delete) and zeroing storage slots provide SSTORE refunds, optimizable in batch operations.[2]
26. Scenario: At Atlassian, implement an upgradeable proxy pattern.
Use a proxy contract with delegatecall to implementation, storing logic address and ensuring storage layout compatibility.[2]
27. What is an anonymous event in Solidity?
Anonymous events omit indexed topics, saving gas but harder to filter: event Transfer(address indexed from, address indexed to, uint value) anonymous;.[2]
28. How many arguments can a Solidity event have?
Events support up to 3 indexed arguments for efficient log filtering; additional non-indexed args go in data.[2]
29. Gas-efficient alternative to multiplying/dividing by powers of two?
Use left/right shifts: x << 3 for x*8, x >> 2 for x/4, cheaper than multiplication/division.[2]
30. Scenario: At Adobe, compute address(this).balance efficiently.
Use address(this).balance opcode BALANCE for current contract Ether balance without external calls.[2]