Questions tagged [local-variables]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
24 views

Solidity variable for contract scope (not state variables)?

I use state variables for the interaction of calls (fallback) between contracts. But copying and clearing state variables uses a lot of gas. Perhaps there is a better practice, how to have temporary ...
Andriy's user avatar
  • 1
0 votes
1 answer
27 views

Preserving gwei after math

Is it possible to preserve a currency designation after performing calculations? For example, using Remix, in variable declaration I have something like this: uint256 myConstant = 100 gwei; uint256 ...
Mat's user avatar
  • 5
1 vote
1 answer
125 views

How to silence warnings in return variables when they are not used?

I have the following function in solidity: function validateAndPayForPaymasterTransaction( bytes32, bytes32, Transaction calldata _transaction ) external payable override onlyBootloader ...
Falcon Stakepool's user avatar
0 votes
1 answer
251 views

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

I have an issue with my code, I want to create a function to be able to Mint a token, and add a struct to represent all attributes of this token. The issue is, I have lot's of args on my function (8) ...
Arthur's user avatar
  • 194
0 votes
1 answer
128 views

Warning: This declaration shadows an existing declaration

Can you please help me out with this code, where I get the six warnings shown bellow? As a result, the withdrawal doesn't go through with the specified amount. But I don't know how to get around it. ...
f22daniel's user avatar
  • 313
1 vote
0 answers
18 views

Just how cheap are computations with local variables?

Beginner question: I have a function that needs to make many (potentially thousands or hundreds of thousands) of computations. Naturally I'm worried that the gas cost will make this unusable. I've ...
King Arthur's user avatar
0 votes
1 answer
235 views

Local variables in solidity

I have a couple of questions regarding local variables and creating structs and arrays. As I understand they can be stored in memory and in storage. If they defined as state variables they will be ...
Alex's user avatar
  • 3
0 votes
0 answers
331 views

passing multiple parameters to deploy script (ethers, upgrades)

I'm looking for the tutorial or instruction manual for parameter syntax My solidity file has the following initializer: function initialize( address addy, string memory _var1, string ...
CQM's user avatar
  • 157
0 votes
1 answer
29 views

Remix does not show openzeppelin counter variable in Debugger

My local x variable is appearing in the debugger, why is the game_id variable not showing up?
Danny B's user avatar
  • 323
0 votes
1 answer
107 views

Understanding local variables named as same in diffrent functions and modifiers

I'm confused while understanding the local variable _txId is used in several functions and modifiers, do they all have the same value or are they independent for each call. I read that local variables ...
R.V's user avatar
  • 96
1 vote
1 answer
74 views

Memory to memory assignment doesn't point to the same reference

Hey I am trying to understand data location more it is stated in the docs that "Assignments from memory to memory only create references. This means that changes to one memory variable are also ...
jmsandiegoo's user avatar
1 vote
1 answer
533 views

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

Say I define a struct named MyStruct and a local variable called myStruct, what is the most gas efficient way to assign/update 1 or more fields/members of myStruct? If I wanted to assign a new value ...
MShakeG's user avatar
  • 1,418
1 vote
1 answer
691 views

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

In solidity does declaring a variable inside a while or for loop result in that variable being redeclared during each loop iteration? And if so does that make it less gas efficient than say declaring ...
MShakeG's user avatar
  • 1,418
1 vote
0 answers
50 views

Dapptools Fork Impersonation?

In hardhat, theres a way to 'impersonateSigner' and fake a signature from an address you dont own on a forked mainnet; is there a way to do the same with seth? Naively setting the sender doesnt let me ...
John Targaryen's user avatar
0 votes
1 answer
26 views

variable in WGAME woolf.sol confuses me

Okay, so I was looking over the wolf contract(https://etherscan.io/address/0xeb834ae72b30866af20a6ce5440fa598bfad3a42#code), to understand how they fixed it and what happened... and one thing just ...
Devon Margaret Martens's user avatar
0 votes
0 answers
25 views

Stack too deep, try removing local variables when using remix [duplicate]

while compiling in remix i get the above error: CompilerError: Stack too deep, try removing local variables. --> work/youkie.sol:1015:80: | 1015 | (uint256 rAmount, uint256 ...
stofu's user avatar
  • 93
1 vote
1 answer
51 views

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

How can I access totalSupply after refactoring to using a _mint function instead of local state? I will need this to make transfers from the owner to another address. Does this example show that this ...
Dmitry Dyachkov's user avatar
0 votes
0 answers
115 views

Unable to change/read local variable in a smart contract on a local private geth blockchain

I trying to create and test an ERC-20 Token on a local geth blockchain. I tried compiling and testing my contract on Remix's Javascript VM environment and it works fine. Then, I wanted to try ...
Aleksi Daskalov's user avatar
6 votes
1 answer
358 views

Public variable getter shows as transaction in Remix

As of Solidity 0.6.0+ compiler, my remix shows getter functions, built by public variables, as transactions and, therefore, do not return the value. I searched the solidity 0.6.0 breaking changes but ...
João Quintanilha's user avatar
1 vote
0 answers
27 views

What's the best way to send many strings in only one call?

So I have to write on-chain about 15 string key-value pairs in one call. Of course, I took the naive approach first by putting all those strings as arguments of my contract, but then I run onto the 16 ...
Thibaut Dumont's user avatar
0 votes
1 answer
26 views

Error accesing variables from other solidity file

I get a error when I call to the getVal function inside testToken file. The EVM return me the following: call to testCoin.getVal errored: VM error: revert. revert The transaction has been reverted ...
UnexpectedCharacter's user avatar
4 votes
1 answer
443 views

Pointing to other contracts in solidity?

I'm doing the CryptoZombies tutorial to get a better handle on solidity and in one of the chapters it contains the following code pragma solidity ^0.4.19; import "./zombiefactory.sol"; contract ...
user8972341's user avatar
2 votes
3 answers
1k views

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

According to this answer, it says simpler variables like bool, uint, et cetera are not variable in length, and are therefore defaulted to memory, whereas this one mentions uint256 v; is default to ...
bbusdriver's user avatar
  • 1,114
6 votes
1 answer
545 views

Truffle debug on function call show null variables

With a truffle version of 4.1.0, using truffle debug on a call of my contract function below: function Deposit (uint256 timeout, bytes32 hash, address recipient) public payable returns (...
Shiri's user avatar
  • 766
2 votes
1 answer
381 views

local var inside a function modifies another state variable

I have this very simple contract: pragma solidity ^0.4.18; contract C{ uint public a = 9; uint[] public data; function f(uint _a) public{ a = _a; uint[] y; ...
Dany D's user avatar
  • 145
2 votes
1 answer
110 views

Examples of functions limitations?

I coded different functions and didn't find a standard that define crystal clear how many variables you can use (fields, local or as parameters of modifiers inside this function? Do you know a ...
Mario Granero's user avatar
5 votes
2 answers
1k views

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

I have a contract that's doing a fairly complex calculation with some intermediate calculations, and I'm running into the "stack too deep" problem. I've tried to use a memory array within the ...
carlolm's user avatar
  • 2,316
0 votes
0 answers
649 views

Truffle: errors when I try to access variables of a ERC20 token contract

I got a few errors when I try to access variables of a ERC20 token contract. The contract is the "Sample fixed supply token contract" from https://theethereum.wiki/w/index.php/ERC20_Token_Standard ...
David Young's user avatar
2 votes
1 answer
724 views

State Variable Storage in Contracts

I'm learning Solidity. According to the docs, variables are permanently stored in contract storage. From my understanding (I may be wrong), the details are on the blockchain. My question is, how do I ...
Some User's user avatar
  • 285
13 votes
2 answers
13k views

Local variable and state variable, and the difference between them

I am new to solidity. When I read the solidity documentation, it says local variable and state variable. But I can't find the definition of the two terms. Can anyone explain the meaning of local ...
dingdang's user avatar
  • 175
5 votes
2 answers
2k views

Local storage variable

I am reading the solidity docs here and I seem to be struggling to understand the following. Data locations are important because they change how assignments behave: assignments between ...
Bobo's user avatar
  • 244