Web3 Interview Questions - Easy
Easy-level Web3 interview questions covering blockchain fundamentals, Ethereum, smart contracts, and decentralized applications.
Q1: What is blockchain and how does it work?
Answer:
Block Structure
Key Components:
- Block: Container of transactions
- Hash: Unique identifier (SHA-256)
- Previous Hash: Links to previous block
- Timestamp: When block was created
- Nonce: Number used in mining
- Transactions: List of transfers/operations
How It Works
Properties:
- Decentralized: No single authority
- Transparent: All transactions visible
- Immutable: Cannot change past blocks
- Secure: Cryptographically protected
Q2: What is Ethereum and how does it differ from Bitcoin?
Answer:
Bitcoin vs Ethereum
Comparison:
| Feature | Bitcoin | Ethereum |
|---|---|---|
| Purpose | Digital currency | Decentralized platform |
| Block Time | ~10 minutes | ~12 seconds |
| Supply | 21M cap | No hard cap |
| Scripting | Limited | Turing complete |
| Consensus | PoW | PoS (after Merge) |
Q3: What is a smart contract?
Answer:
Simple Smart Contract
1// SPDX-License-Identifier: MIT
2pragma solidity ^0.8.0;
3
4contract SimpleStorage {
5 // State variable
6 uint256 private value;
7
8 // Event
9 event ValueChanged(uint256 newValue);
10
11 // Write function
12 function setValue(uint256 _value) public {
13 value = _value;
14 emit ValueChanged(_value);
15 }
16
17 // Read function (view)
18 function getValue() public view returns (uint256) {
19 return value;
20 }
21}
Contract Lifecycle
Characteristics:
- Trustless: No intermediary needed
- Transparent: Code is public
- Immutable: Cannot be changed
- Composable: Can call other contracts
Q4: What are gas and gas fees?
Answer:
Gas Calculation
Formula: $$\text{Transaction Fee} = \text{Gas Used} \times \text{Gas Price}$$
Gas Costs
1contract GasExample {
2 uint256 public value; // Storage: expensive
3
4 // ~43,000 gas (storage write)
5 function setValue(uint256 _value) public {
6 value = _value;
7 }
8
9 // ~23,000 gas (read from storage)
10 function getValue() public view returns (uint256) {
11 return value;
12 }
13
14 // ~21,000 gas (simple transfer)
15 function sendEther(address payable recipient) public payable {
16 recipient.transfer(msg.value);
17 }
18}
Gas Optimization
Gas Price Units:
- 1 Gwei = 10⁹ Wei
- 1 ETH = 10¹⁸ Wei
Q5: What is a wallet and what are public/private keys?
Answer:
Key Relationship
Example:
1Private Key:
20x4c0883a69102937d6231471b5dbb6204fe512961708279f8c5c9e4e6f1b9a91a
3
4Public Key:
50x04a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd5b8dec5235a0fa8722476c7709c02559e3aa73aa03918ba2d492eea75abea235
6
7Address (last 20 bytes of Keccak-256):
80x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed
Wallet Types
Security:
- Never share private key
- Backup seed phrase
- Use hardware wallet for large amounts
- Verify addresses before sending
Q6: What are ERC-20 tokens?
Answer:
ERC-20 Interface
1// SPDX-License-Identifier: MIT
2pragma solidity ^0.8.0;
3
4interface IERC20 {
5 // Returns total token supply
6 function totalSupply() external view returns (uint256);
7
8 // Returns account balance
9 function balanceOf(address account) external view returns (uint256);
10
11 // Transfers tokens
12 function transfer(address recipient, uint256 amount) external returns (bool);
13
14 // Returns remaining allowance
15 function allowance(address owner, address spender) external view returns (uint256);
16
17 // Sets allowance for spender
18 function approve(address spender, uint256 amount) external returns (bool);
19
20 // Transfers from one account to another
21 function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
22
23 // Events
24 event Transfer(address indexed from, address indexed to, uint256 value);
25 event Approval(address indexed owner, address indexed spender, uint256 value);
26}
Simple ERC-20 Implementation
1contract MyToken is IERC20 {
2 string public name = "MyToken";
3 string public symbol = "MTK";
4 uint8 public decimals = 18;
5 uint256 private _totalSupply;
6
7 mapping(address => uint256) private _balances;
8 mapping(address => mapping(address => uint256)) private _allowances;
9
10 constructor(uint256 initialSupply) {
11 _totalSupply = initialSupply * 10**decimals;
12 _balances[msg.sender] = _totalSupply;
13 }
14
15 function totalSupply() public view returns (uint256) {
16 return _totalSupply;
17 }
18
19 function balanceOf(address account) public view returns (uint256) {
20 return _balances[account];
21 }
22
23 function transfer(address recipient, uint256 amount) public returns (bool) {
24 require(_balances[msg.sender] >= amount, "Insufficient balance");
25 _balances[msg.sender] -= amount;
26 _balances[recipient] += amount;
27 emit Transfer(msg.sender, recipient, amount);
28 return true;
29 }
30
31 // ... other functions
32}
Token Flow
Q7: What are NFTs (ERC-721)?
Answer:
ERC-721 vs ERC-20
ERC-721 Interface
1// SPDX-License-Identifier: MIT
2pragma solidity ^0.8.0;
3
4interface IERC721 {
5 // Returns owner of token
6 function ownerOf(uint256 tokenId) external view returns (address);
7
8 // Returns token balance of owner
9 function balanceOf(address owner) external view returns (uint256);
10
11 // Transfers token
12 function transferFrom(address from, address to, uint256 tokenId) external;
13
14 // Safe transfer with callback
15 function safeTransferFrom(address from, address to, uint256 tokenId) external;
16
17 // Approve address to transfer token
18 function approve(address to, uint256 tokenId) external;
19
20 // Set approval for all tokens
21 function setApprovalForAll(address operator, bool approved) external;
22
23 // Events
24 event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
25 event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
26}
Simple NFT
1contract SimpleNFT is IERC721 {
2 string public name = "MyNFT";
3 string public symbol = "MNFT";
4
5 uint256 private _tokenIdCounter;
6 mapping(uint256 => address) private _owners;
7 mapping(address => uint256) private _balances;
8 mapping(uint256 => string) private _tokenURIs;
9
10 function mint(address to, string memory tokenURI) public returns (uint256) {
11 uint256 tokenId = _tokenIdCounter++;
12 _owners[tokenId] = to;
13 _balances[to]++;
14 _tokenURIs[tokenId] = tokenURI;
15
16 emit Transfer(address(0), to, tokenId);
17 return tokenId;
18 }
19
20 function tokenURI(uint256 tokenId) public view returns (string memory) {
21 require(_owners[tokenId] != address(0), "Token doesn't exist");
22 return _tokenURIs[tokenId];
23 }
24
25 // ... other functions
26}
Use Cases:
- Digital art
- Collectibles
- Gaming items
- Real estate
- Identity/credentials
Q8: What is a decentralized application (dApp)?
Answer:
dApp Architecture
Connecting to dApp
1// Using ethers.js
2import { ethers } from 'ethers';
3
4// Connect to MetaMask
5async function connectWallet() {
6 if (typeof window.ethereum !== 'undefined') {
7 // Request account access
8 await window.ethereum.request({ method: 'eth_requestAccounts' });
9
10 // Create provider
11 const provider = new ethers.providers.Web3Provider(window.ethereum);
12
13 // Get signer (user's account)
14 const signer = provider.getSigner();
15
16 // Get address
17 const address = await signer.getAddress();
18 console.log('Connected:', address);
19
20 return { provider, signer, address };
21 } else {
22 alert('Please install MetaMask!');
23 }
24}
25
26// Interact with contract
27async function interactWithContract() {
28 const { provider, signer } = await connectWallet();
29
30 // Contract ABI and address
31 const contractAddress = '0x123...';
32 const abi = [...]; // Contract ABI
33
34 // Create contract instance
35 const contract = new ethers.Contract(contractAddress, abi, signer);
36
37 // Read from contract
38 const value = await contract.getValue();
39 console.log('Value:', value.toString());
40
41 // Write to contract
42 const tx = await contract.setValue(42);
43 await tx.wait(); // Wait for confirmation
44 console.log('Transaction confirmed');
45}
dApp vs Traditional App
Q9: What is Web3.js and Ethers.js?
Answer:
Web3.js Example
1const Web3 = require('web3');
2
3// Connect to Ethereum node
4const web3 = new Web3('https://mainnet.infura.io/v3/YOUR_PROJECT_ID');
5
6// Get balance
7async function getBalance(address) {
8 const balance = await web3.eth.getBalance(address);
9 const eth = web3.utils.fromWei(balance, 'ether');
10 console.log(`Balance: ${eth} ETH`);
11}
12
13// Send transaction
14async function sendTransaction(from, to, amount) {
15 const tx = {
16 from: from,
17 to: to,
18 value: web3.utils.toWei(amount, 'ether'),
19 gas: 21000
20 };
21
22 const receipt = await web3.eth.sendTransaction(tx);
23 console.log('Transaction hash:', receipt.transactionHash);
24}
25
26// Interact with contract
27const abi = [...];
28const contractAddress = '0x123...';
29const contract = new web3.eth.Contract(abi, contractAddress);
30
31// Call view function
32const value = await contract.methods.getValue().call();
33
34// Send transaction to contract
35await contract.methods.setValue(42).send({ from: userAddress });
Ethers.js Example
1const { ethers } = require('ethers');
2
3// Connect to Ethereum node
4const provider = new ethers.providers.JsonRpcProvider(
5 'https://mainnet.infura.io/v3/YOUR_PROJECT_ID'
6);
7
8// Get balance
9async function getBalance(address) {
10 const balance = await provider.getBalance(address);
11 const eth = ethers.utils.formatEther(balance);
12 console.log(`Balance: ${eth} ETH`);
13}
14
15// Send transaction
16async function sendTransaction(wallet, to, amount) {
17 const tx = await wallet.sendTransaction({
18 to: to,
19 value: ethers.utils.parseEther(amount)
20 });
21 await tx.wait();
22 console.log('Transaction hash:', tx.hash);
23}
24
25// Interact with contract
26const abi = [...];
27const contractAddress = '0x123...';
28const contract = new ethers.Contract(contractAddress, abi, provider);
29
30// Call view function
31const value = await contract.getValue();
32
33// Send transaction to contract (need signer)
34const signer = provider.getSigner();
35const contractWithSigner = contract.connect(signer);
36const tx = await contractWithSigner.setValue(42);
37await tx.wait();
Comparison:
| Feature | Web3.js | Ethers.js |
|---|---|---|
| Size | Larger | Smaller |
| API | Callback-based | Promise-based |
| TypeScript | Limited | Excellent |
| Documentation | Good | Excellent |
| Community | Larger | Growing |
Q10: What is IPFS and decentralized storage?
Answer:
IPFS vs HTTP
How IPFS Works
Using IPFS with NFTs
1contract NFTWithIPFS {
2 mapping(uint256 => string) private _tokenURIs;
3
4 function mint(address to, uint256 tokenId, string memory ipfsHash) public {
5 // Store IPFS hash as token URI
6 _tokenURIs[tokenId] = string(abi.encodePacked("ipfs://", ipfsHash));
7 _mint(to, tokenId);
8 }
9
10 function tokenURI(uint256 tokenId) public view returns (string memory) {
11 return _tokenURIs[tokenId];
12 }
13}
1// Upload to IPFS
2const IPFS = require('ipfs-http-client');
3const ipfs = IPFS.create({ host: 'ipfs.infura.io', port: 5001, protocol: 'https' });
4
5async function uploadToIPFS(file) {
6 const added = await ipfs.add(file);
7 const cid = added.path;
8 console.log('IPFS CID:', cid);
9 // Returns: QmXyz...
10
11 // Access via: https://ipfs.io/ipfs/QmXyz...
12 return cid;
13}
14
15// NFT Metadata
16const metadata = {
17 name: "My NFT",
18 description: "A cool NFT",
19 image: "ipfs://QmImageHash...",
20 attributes: [
21 { trait_type: "Color", value: "Blue" },
22 { trait_type: "Rarity", value: "Rare" }
23 ]
24};
25
26const metadataCID = await uploadToIPFS(JSON.stringify(metadata));
Decentralized Storage Options:
- IPFS: Content-addressed, P2P
- Arweave: Permanent storage, pay once
- Filecoin: Incentivized storage network
- Swarm: Ethereum-native storage
Summary
Key Web3 concepts:
- Blockchain: Distributed ledger, immutable, cryptographic
- Ethereum: Smart contract platform, EVM, gas
- Smart Contracts: Self-executing code on blockchain
- Gas: Computation cost, prevents spam
- Wallets: Private/public keys, addresses
- ERC-20: Fungible token standard
- NFTs (ERC-721): Non-fungible tokens, unique assets
- dApps: Decentralized applications
- Web3.js/Ethers.js: JavaScript libraries for Ethereum
- IPFS: Decentralized storage, content-addressed
These fundamentals are essential for Web3 development.
Related Snippets
- Bitcoin (Nakamoto) Consensus Interview Questions
Bitcoin consensus algorithm interview questions covering Proof-of-Work (PoW) and … - Byzantine Fault Tolerance (BFT) Consensus Interview Questions
Byzantine Fault Tolerance (BFT) consensus algorithm interview questions covering … - Cardano Interview Questions - Easy
Easy-level Cardano interview questions covering blockchain basics, Plutus, and … - Cardano Interview Questions - Hard
Hard-level Cardano interview questions covering advanced optimization and formal … - Cardano Interview Questions - Medium
Medium-level Cardano interview questions covering advanced Plutus development … - Consensus Algorithms Comparison Interview Questions
Consensus algorithm comparison and general implementation interview questions. … - Cosmos Chain Operations Interview Questions - Easy
Easy-level Cosmos chain operation interview questions covering chain operations, … - Cosmos Chain Operations Interview Questions - Hard
Hard-level Cosmos chain operation questions covering advanced algorithms, … - Cosmos Chain Operations Interview Questions - Medium
Medium-level Cosmos chain operation questions covering advanced chain … - Cosmos SDK Interview Questions - Easy
Easy-level Cosmos SDK interview questions covering chain code, SDK basics, and … - Cosmos SDK Interview Questions - Hard
Hard-level Cosmos SDK interview questions covering advanced SDK internals, … - Cosmos SDK Interview Questions - Medium
Medium-level Cosmos SDK interview questions covering advanced module … - Ethereum Proof-of-Stake Consensus Interview Questions
Ethereum Proof-of-Stake consensus algorithm interview questions covering Casper … - Ouroboros (Cardano) Consensus Interview Questions
Ouroboros consensus algorithm interview questions covering Cardano's … - Paxos Consensus Interview Questions
Paxos consensus algorithm interview questions covering the classic distributed … - Polkadot (NPoS) Consensus Interview Questions
Polkadot consensus algorithm interview questions covering Nominated … - Polkadot Interview Questions - Easy
Easy-level Polkadot interview questions covering blockchain basics, Substrate, … - Polkadot Interview Questions - Hard
Hard-level Polkadot interview questions covering advanced optimization and … - Polkadot Interview Questions - Medium
Medium-level Polkadot interview questions covering advanced Substrate … - Solana Interview Questions - Easy
Easy-level Solana interview questions covering blockchain basics, programs, and … - Solana Interview Questions - Hard
Hard-level Solana interview questions covering advanced optimization, security, … - Solana Interview Questions - Medium
Medium-level Solana interview questions covering advanced program development, … - Solana Proof of History Consensus Interview Questions
Solana consensus algorithm interview questions covering Proof of History (PoH) … - Tendermint Consensus Interview Questions
Tendermint consensus algorithm interview questions covering the Byzantine Fault … - Web3 Interview Questions - Hard
Hard-level Web3 interview questions covering MEV, zero-knowledge proofs, … - Web3 Interview Questions - Medium
Medium-level Web3 interview questions covering DeFi, advanced Solidity, …