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:

graph TB
    A[Blockchain] --> B[Distributed<br/>Ledger]
    A --> C[Immutable<br/>Records]
    A --> D[Cryptographic<br/>Hashing]
    A --> E[Consensus<br/>Mechanism]
    
    style A fill:#FFD700

Block Structure

graph LR
    A[Block N-1] --> B[Block N]
    B --> C[Block N+1]
    
    B --> D[Header]
    B --> E[Transactions]
    
    D --> F[Previous Hash]
    D --> G[Timestamp]
    D --> H[Nonce]
    D --> I[Merkle Root]
    
    style B fill:#FFD700

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

sequenceDiagram
    participant U as User
    participant N as Network
    participant M as Miner
    participant B as Blockchain
    
    U->>N: Submit transaction
    N->>N: Broadcast to nodes
    M->>M: Collect transactions
    M->>M: Mine block (find nonce)
    M->>N: Broadcast new block
    N->>N: Validate block
    N->>B: Add to chain

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:

graph TB
    A[Ethereum] --> B[Smart Contracts<br/>Programmable]
    A --> C[Turing Complete<br/>Any computation]
    A --> D[EVM<br/>Execution environment]
    A --> E[Gas<br/>Computation cost]
    
    style A fill:#FFD700

Bitcoin vs Ethereum

graph TB
    subgraph Bitcoin
        B1[Digital Currency]
        B2[Store of Value]
        B3[Limited Scripts]
        B4[UTXO Model]
    end
    
    subgraph Ethereum
        E1[World Computer]
        E2[Smart Contracts]
        E3[Turing Complete]
        E4[Account Model]
    end

Comparison:

FeatureBitcoinEthereum
PurposeDigital currencyDecentralized platform
Block Time~10 minutes~12 seconds
Supply21M capNo hard cap
ScriptingLimitedTuring complete
ConsensusPoWPoS (after Merge)

Q3: What is a smart contract?

Answer:

graph TB
    A[Smart Contract] --> B[Self-Executing<br/>Code]
    A --> C[Stored on<br/>Blockchain]
    A --> D[Immutable<br/>Once deployed]
    A --> E[Deterministic<br/>Same input = same output]
    
    style A fill:#FFD700

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

sequenceDiagram
    participant D as Developer
    participant C as Compiler
    participant N as Network
    participant B as Blockchain
    
    D->>C: Write Solidity code
    C->>C: Compile to bytecode
    C->>N: Deploy transaction
    N->>B: Store contract
    
    Note over B: Contract at address 0x123...
    
    participant U as User
    U->>B: Call setValue(42)
    B->>B: Execute code
    B->>U: Transaction receipt

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:

graph TB
    A[Gas] --> B[Computation<br/>Cost]
    A --> C[Prevents Spam<br/>& Infinite loops]
    A --> D[Paid in ETH<br/>To miners/validators]
    
    style A fill:#FFD700

Gas Calculation

graph LR
    A[Transaction] --> B[Gas Limit<br/>Max units]
    A --> C[Gas Price<br/>Wei per unit]
    
    B --> D[Total Fee]
    C --> D
    
    D --> E[Gas Used × Gas Price]
    
    style D fill:#FFD700

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

graph TB
    A[Optimize Gas] --> B1[Use memory<br/>not storage]
    A --> B2[Batch operations]
    A --> B3[Use events<br/>not storage]
    A --> B4[Minimize loops]
    A --> B5[Use uint256<br/>not smaller types]
    
    style A fill:#FFD700

Gas Price Units:

  • 1 Gwei = 10⁹ Wei
  • 1 ETH = 10¹⁸ Wei

Q5: What is a wallet and what are public/private keys?

Answer:

graph TB
    A[Wallet] --> B[Private Key<br/>Secret]
    A --> C[Public Key<br/>Derived from private]
    A --> D[Address<br/>Derived from public]
    
    B --> E[Sign Transactions]
    C --> F[Verify Signatures]
    D --> G[Receive Funds]
    
    style A fill:#FFD700
    style B fill:#FF6B6B

Key Relationship

graph LR
    A[Private Key<br/>256 bits random] --> B[Public Key<br/>ECDSA secp256k1]
    B --> C[Address<br/>Keccak-256 hash]
    
    style A fill:#FF6B6B
    style C fill:#90EE90

Example:

1Private Key: 
20x4c0883a69102937d6231471b5dbb6204fe512961708279f8c5c9e4e6f1b9a91a
3
4Public Key:
50x04a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd5b8dec5235a0fa8722476c7709c02559e3aa73aa03918ba2d492eea75abea235
6
7Address (last 20 bytes of Keccak-256):
80x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed

Wallet Types

graph TB
    A[Wallet Types] --> B[Hot Wallet<br/>Connected to internet]
    A --> C[Cold Wallet<br/>Offline storage]
    
    B --> D1[MetaMask<br/>Browser extension]
    B --> D2[Mobile Wallet<br/>Trust Wallet]
    
    C --> E1[Hardware Wallet<br/>Ledger, Trezor]
    C --> E2[Paper Wallet<br/>Printed keys]
    
    style B fill:#FFD700
    style C fill:#90EE90

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:

graph TB
    A[ERC-20] --> B[Fungible Token<br/>Standard]
    A --> C[Interchangeable<br/>Units]
    A --> D[Standard Interface<br/>6 functions]
    
    style A fill:#FFD700

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

sequenceDiagram
    participant A as Alice
    participant T as Token Contract
    participant B as Bob
    
    A->>T: transfer(Bob, 100)
    T->>T: Check balance
    T->>T: Update balances
    T->>B: Emit Transfer event
    
    Note over A: Balance: 900
    Note over B: Balance: 100

Q7: What are NFTs (ERC-721)?

Answer:

graph TB
    A[NFT<br/>Non-Fungible Token] --> B[Unique<br/>Each token different]
    A --> C[Indivisible<br/>Cannot split]
    A --> D[Provable Ownership<br/>On-chain]
    A --> E[ERC-721<br/>Standard]
    
    style A fill:#FFD700

ERC-721 vs ERC-20

graph TB
    subgraph ERC-20["ERC-20 (Fungible)"]
        F1[1 USDC = 1 USDC]
        F2[Divisible]
        F3[Interchangeable]
    end
    
    subgraph ERC-721["ERC-721 (Non-Fungible)"]
        N1[Token #1 ≠ Token #2]
        N2[Indivisible]
        N3[Unique]
    end

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:

graph TB
    A[dApp] --> B[Frontend<br/>Web/Mobile UI]
    A --> C[Smart Contracts<br/>Backend logic]
    A --> D[Blockchain<br/>Data storage]
    A --> E[No Central Server<br/>Decentralized]
    
    style A fill:#FFD700

dApp Architecture

graph TB
    A[User Browser] --> B[Frontend<br/>HTML/CSS/JS]
    B --> C[Web3.js/Ethers.js<br/>Library]
    C --> D[Wallet<br/>MetaMask]
    D --> E[Ethereum Node<br/>Infura/Alchemy]
    E --> F[Smart Contracts<br/>On-chain]
    
    style A fill:#FFE4B5
    style F fill:#90EE90

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

graph TB
    subgraph Traditional["Traditional App"]
        T1[Centralized Server]
        T2[Company Controls Data]
        T3[Single Point of Failure]
        T4[Trust Required]
    end
    
    subgraph dApp["Decentralized App"]
        D1[Distributed Network]
        D2[User Controls Data]
        D3[No Single Point of Failure]
        D4[Trustless]
    end

Q9: What is Web3.js and Ethers.js?

Answer:

graph TB
    A[JavaScript<br/>Libraries] --> B[Web3.js<br/>Original library]
    A --> C[Ethers.js<br/>Modern alternative]
    
    B --> D[Connect to<br/>Ethereum]
    C --> D
    
    D --> E[Read blockchain]
    D --> F[Send transactions]
    D --> G[Interact with contracts]
    
    style A fill:#FFD700

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:

FeatureWeb3.jsEthers.js
SizeLargerSmaller
APICallback-basedPromise-based
TypeScriptLimitedExcellent
DocumentationGoodExcellent
CommunityLargerGrowing

Q10: What is IPFS and decentralized storage?

Answer:

graph TB
    A[IPFS<br/>InterPlanetary<br/>File System] --> B[Content-Addressed<br/>Hash-based]
    A --> C[Distributed<br/>P2P network]
    A --> D[Permanent<br/>Immutable]
    
    style A fill:#FFD700

IPFS vs HTTP

graph TB
    subgraph HTTP["HTTP (Location-based)"]
        H1[https://example.com/file.jpg]
        H2[Server location]
        H3[Can change/disappear]
    end
    
    subgraph IPFS["IPFS (Content-based)"]
        I1[ipfs://Qm...]
        I2[Content hash]
        I3[Permanent & verifiable]
    end

How IPFS Works

sequenceDiagram
    participant U as User
    participant N as IPFS Node
    participant P as Peer Network
    
    U->>N: Add file
    N->>N: Calculate hash (CID)
    N->>P: Announce content
    
    Note over N: CID: QmXyz...
    
    participant U2 as Another User
    U2->>P: Request QmXyz...
    P->>P: Find nodes with content
    P->>U2: Download from nearest nodes

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