Prepare for the Blockchain Developer Certification. Master blockchain concepts with flashcards and multiple choice questions. Explanation-based learning for your success!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


Which of the following statements is true regarding setters and getters in smart contracts?

  1. Setters require transactions; Getters do not

  2. Getters require transactions; Setters do not

  3. Both require transactions

  4. Neither requires transactions

The correct answer is: Setters require transactions; Getters do not

The statement that setters require transactions while getters do not is accurate. In the context of smart contracts, setters are functions used to change or update state variables. When you call a setter function, you are effectively modifying the blockchain's state, which necessitates a transaction. This transaction must be processed by the network and confirmed by miners or validators, which incurs gas fees. On the other hand, getters are functions that simply retrieve the value of state variables without altering them. Since no state change is made during a getter function call, it can be read from the blockchain without needing a transaction. This means that calling a getter can be done locally or via a query without incurring gas costs associated with transactions. This understanding clarifies the distinction between state-altering functions and read-only functions in smart contracts, fundamentally shaping how developers interact with blockchain data.