Skip to main content
Share Your Experience: Take the 2024 Developer Survey
20 votes
Accepted

Local variable and state variable, and the difference between them

State Variables From the solidity docs here, State variables are values which are permanently stored in contract storage. and can be declared in a contract as follow, contract SimpleStorage { ...
Achala Dissanayake's user avatar
3 votes
Accepted

Pointing to other contracts in solidity?

KittyInterface kittyContract = KittyInterface(ckAddress); ckAddress is not being passed as a parameter to anything. This is a cast (like uint256(5) or address(0)). The line is saying "ckAddress is ...
user19510's user avatar
  • 28.1k
3 votes

local var inside a function modifies another state variable

You are declaring y as a storage but you left unitialized so y points to the same slot than a. The first 32 bytes of an array in storage is the array length, and after that follows the data. So the ...
Ismael's user avatar
  • 30.5k
3 votes
Accepted

Stack too deep | Use memory array to store many "local" variables?

So my temp variable assignments were causing the problem. It works if limiting to 8 assignments at a time: This fails (9 variable assignments): (temp[0], temp[1], temp[2], temp[3], temp[4], temp[5],...
carlolm's user avatar
  • 2,326
2 votes

Stack too deep | Use memory array to store many "local" variables?

Maybe you've tried this but some debugging in Remix with empty getter() and someOperation() functions that just return values shows the max stack depth reaches 12 items when I use the first method but ...
willjgriff's user avatar
  • 1,658
2 votes

Local variable and state variable, and the difference between them

in simple terms: is all about the scopes we consider as states all variables defined outside the scope of the defined functions (we can consider them as global variables) whereas local variables are ...
Badr Bellaj's user avatar
  • 18.8k
2 votes

Truffle debug on function call show null variables

I believe this was a bug before which is fixed now. Current version i'm using is: $ truffle version Truffle v5.0.20 (core: 5.0.20) Solidity v0.5.0 (solc-js) Node v10.15.3 Web3.js v1.0.0-beta.37 ...
Greg Jeanmart's user avatar
2 votes
Accepted

Local storage variable

Value assignment to a variable can be done by either giving a reference or creating an independent copy. If it's a reference when the original one which is assigned to the variable get changed value ...
Achala Dissanayake's user avatar
2 votes
Accepted

What is the most gas efficient way to initialise a struct?

So I ran all 4 scenarios in remix as this is what I found, when assigning new values to all fields in myStruct option 1 is indeed cheaper than option 2, and when updating selected fields in myStruct ...
MShakeG's user avatar
  • 1,703
2 votes
Accepted

Is it more gas efficient to declare variable inside or outside of a for or while loop?

This kind of questions are easiest to just test. So I created a contract in Remix and ran both of the functions. The first a costs 25201 gas and b costs 25260 gas. Therefore it's cheaper to to declare ...
Lauri Peltonen's user avatar
2 votes
Accepted

Total Supply manipulation after moving to a new standard with _mint function

Now totalSupply is a function if you need its value. You can modify it by using _mint and _burn. If the tokens were already assigned to the owner it can transfer them directly.
Ismael's user avatar
  • 30.5k
2 votes
Accepted

Public variable getter shows as transaction in Remix

The problem is related to the ABI JSON produced by the compiler and how the tools use it to determine if a function is view or pure. As you can see in the docs: The fields constant and payable ...
alberto's user avatar
  • 3,343
2 votes
Accepted

Error accesing variables from other solidity file

In the latter example “value” is an empty pointer. You do not initialize it. Assign to it the proper value and all works flawlessly. The easiest way is to have a constructor passing the address of ...
Rick Park's user avatar
  • 3,194
1 vote
Accepted

Storage variables or event log

Blockchain Storage variable is like a box, they hold data for the contract to use later, but they cost more and event logs are like a notice board: record something that happened during a transaction ...
Awais Ahmad's user avatar
1 vote
Accepted

Mint and Create a Struct give me give me error "Stack too deep try removing local variables"

The "stack too deep" error in Solidity is caused when the execution stack exceeds its maximum size. This can happen when a contract has too many local variables, or when a function calls ...
VX3's user avatar
  • 666
1 vote

Remix does not show openzeppelin counter variable in Debugger

I think its because it was Private State Variable
sms's user avatar
  • 191
1 vote

value types(uint, bool, etc) as local variable is set to memory initially?

It is confusing indeed. The docs state that by default: Parameters (also return) of functions: memory. All other local variables: storage But variables defined in the scope of a function are not ...
Jaime's user avatar
  • 8,350
1 vote
Accepted

Examples of functions limitations?

I'm not aware of any cheat sheet and the problem is that Solidity checks for local stack size in several different places during a function call but emits the same error message, so depending on how ...
Theo Port's user avatar
  • 331
1 vote

Local storage variable

Apart from the accepted answer, I think it's needed to identify what data locations are as well. Documentation provides a good description on available data locations. Data location Every reference ...
Refiner's user avatar
  • 157

Only top scored, non community-wiki answers of a minimum length are eligible