Ethereum Developer Web3.js, Ethers.js and Ethereum APIs 2 β Questions and Answers
Question 1: What does `eth_call` do in contrast to `eth_sendTransaction`?
- eth_call simulates a call without modifying state; eth_sendTransaction writes to the chain (Correct answer)
- eth_call sends ETH while eth_sendTransaction calls functions
- eth_call requires a signed transaction; eth_sendTransaction does not
- eth_call is deprecated and replaced by eth_sendTransaction
Correct answer: eth_call simulates a call without modifying state; eth_sendTransaction writes to the chain
`eth_call` executes a function locally without creating a transaction, while `eth_sendTransaction` broadcasts a state-changing transaction.
Question 2: What is the unit `Wei` in Ethereum?
- The smallest denomination of Ether (1 ETH = 10^18 Wei) (Correct answer)
- The gas unit used to price transactions
- The block reward paid to validators
- A unit representing one billionth of an ETH
Correct answer: The smallest denomination of Ether (1 ETH = 10^18 Wei)
Wei is the smallest indivisible unit of Ether, with 1 ETH equal to 1,000,000,000,000,000,000 (10^18) Wei.
Question 3: What is an Ethereum event filter used for in ethers.js?
- To listen for and query specific smart contract events emitted on-chain (Correct answer)
- To restrict which addresses can call a contract
- To filter out spam transactions in a block
- To set gas price limits for outgoing transactions
Correct answer: To listen for and query specific smart contract events emitted on-chain
Event filters in ethers.js allow developers to subscribe to or query specific contract events by topic and address.
Question 4: What does the `nonce` in an Ethereum transaction represent?
- The number of transactions sent from the sender's address, used to order and deduplicate transactions (Correct answer)
- A random value used in proof-of-work mining
- The amount of gas pre-authorized for the transaction
- A timestamp preventing transaction replay
Correct answer: The number of transactions sent from the sender's address, used to order and deduplicate transactions
The nonce is a sequential counter for each account ensuring transactions execute in order and preventing replay attacks.
Question 5: What is the purpose of `eth_getLogs` in Ethereum's JSON-RPC API?
- To retrieve historical event logs matching a given filter (Correct answer)
- To fetch a list of all transactions in a block
- To get the system logs of an Ethereum node
- To return the execution trace of a transaction
Correct answer: To retrieve historical event logs matching a given filter
`eth_getLogs` returns an array of log objects matching the specified filter (address, topics, block range) from the blockchain.
Question 6: In ethers.js v6, how do you convert a value from Ether to Wei?
- ethers.parseEther('1.0') (Correct answer)
- ethers.utils.toWei('1.0')
- ethers.BigNumber.fromEther(1.0)
- ethers.formatEther(1.0)
Correct answer: ethers.parseEther('1.0')
In ethers.js v6, `ethers.parseEther()` converts an Ether string to its Wei equivalent as a BigInt.
What does `eth_call` do in contrast to `eth_sendTransaction`?