Does the size of a state variable in a smart contract's storage impact the cost of a transaction, even if the variable is not accessed by the executed method? And if it does, to what extend?

For example, in this contract, there's a variable numbers.

contract Example {

   uint[] public numbers;

   function randomOperation() public view returns(uint) {
      return 2 + 2;


Let's assume that variable contains a very large number of entries, will the cost of randomOperation() be affected by that? Also, if I do modify numbers (adding an entry), will the number of entries affect the transaction cost?

2 Answers 2


The reads and writes are deterministic and of constant complexity for the same Data Element Type and Data Element Size, the current size (amount of elements) of an array or a mapping has no impact.

  • If said array has a dynamic size, and a huge amount of entries, would that impact the cost of a write or read? Commented Mar 1, 2023 at 12:44
  • Exactly, no matter how many entries are in the array or mapping, the reads and writes by index or by key will cost the same
    – tenbits
    Commented Mar 1, 2023 at 18:29

State variables are stored directly on the blockchain so they can impact the transaction cost if modification of that state variable is being done in that transaction.

As in your scenario, the transaction doesn't involve modification in the state variable of the contract, therefor the transaction fees won't be affected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.