Questions tagged [local-variables]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
1answer
14 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 ...
1
vote
1answer
12 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 ...
1
vote
0answers
11 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 ...
0
votes
1answer
14 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 ...
0
votes
0answers
20 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 ...
1
vote
1answer
30 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 ...
0
votes
0answers
99 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 ...
6
votes
1answer
218 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 ...
1
vote
0answers
24 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 ...
0
votes
1answer
22 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 ...
3
votes
1answer
332 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 ...
1
vote
3answers
638 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 ...
6
votes
1answer
439 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 (...
2
votes
1answer
349 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; ...
2
votes
1answer
101 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 ...
5
votes
2answers
799 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 ...
0
votes
0answers
588 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 ...
2
votes
1answer
503 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 ...
13
votes
2answers
11k 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 ...
4
votes
2answers
839 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 ...