Questions tagged [state-variable]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
0answers
23 views

Retrieving a State_object value on go-ethereum

I have a deployed contract address and I need to query a contract storage value, a token account balance that is stored on a mapping variable: mapping (address => uint256) balances; From go-...
0
votes
1answer
26 views

Why string variable must be memory from solidity v5.0?

May someone explain me why exactly string variable must be memory from solidity v5.0 and what does tha mean? Thanks for your help.
-1
votes
2answers
82 views

Truffle uint test script not updating storage variable, and strange behaviour

while testing I got a strange behavior of truffle, please see the subject smart contract code first uint256 public burningRatePercent = 50; function onlyOwnerSetBurningRate(uint256 ...
0
votes
2answers
47 views

Accessing private variables using assembly

I would like program an oracle service which I would like to charge a fee for. Therefore, I would store the data of interest as a private variable in my oracle contract. This private variable should ...
2
votes
1answer
16 views

defining storage literals in Solidity

I am trying to write unit tests on functions that take in a storage reference as parameters. There is not much great documentation around how to create literals for these types. These include: address ...
1
vote
1answer
87 views

state variable value not changing

I have very simple solidity code as below - pragma solidity ^0.5.6; contract SaveData { uint public salary; function setSalary(uint input) public { salary=input; } function ...
1
vote
1answer
30 views

Does a storage array have a unique address on the block-chain?

The question in the title is a little vague, so I will try to explain here. Suppose I have a contract with a storage array: pragma solidity 0.4.24; contract MyContract { uint256[10] public ...
0
votes
1answer
81 views

dApp Tech Stack

So I'm looking into building a dApp with standard app I functionality like user login/posts/likes/comments etc. Along with harnessing the power of ethereum to support betting and donations. Here is ...
1
vote
1answer
209 views

How State variable are stored and updated?

The Smart contract and the state variables are stored in the blockchain, let us say during deployment of a smart contract the state variable and smart contracts are stored in the block 1, and in ...
1
vote
1answer
97 views

Are constant state variables cached in the EVM?

From the docs: constant for state variables: Disallows assignment (except initialisation), does not occupy storage slot. Does this mean that the EVM caches constants across all contracts using ...
1
vote
1answer
19 views

Accessing the Ethereum State Variables using web3js (Java Script)

I'm trying to run the below code to get the state variables using the getIdBytes method of the Smart Contract, and assign it to a java script array variable, but it doesn't seem to work. All I can ...
4
votes
1answer
218 views

What are 'payable' state variables?

https://solidity.readthedocs.io/en/latest/solidity-by-example.html#simple-open-auction pragma solidity ^0.4.22; contract SimpleAuction { address payable public beneficiary; What exactly does ...
0
votes
1answer
12 views

Setting Contract level variables

I'm a Python Developer jumping into Solidity and I feel like I'm missing something about variables and scope. How do I set and access variables outside of a function's scope? I can't seem to add ...
1
vote
2answers
182 views

Abi to call value

how to calculate ABI to call some variable in contract? for example contract X { uint data; function Y(uint a) {} } How to calculate signature to call variable "data" ? I know to call ...
0
votes
1answer
464 views

What does “_” mean before a variable name?

I'm a beginner, just recently started reading the docs for Solidity. I can't seem to find this anywhere on google. What does the underscore mean when placed with the indexed keyword? Examples: _from ...
1
vote
0answers
28 views

Best way to restore historical storage state

What is the best way to get historical storage state, given db with current world state and blockchain data? Do I need to reverse assemby code or can I do this using receipt logs?
0
votes
2answers
203 views

In solidity smart contracts how do you access internal state variables declared in the constructor?

I'm working with a solidity contract that declares a state variable in the constructor like this this: constructor( address vault, address proxy ) public MarginAdmin() { state ...
0
votes
0answers
43 views

Can we issue a token with specific local state?

Will it be possible to create an ERC20-Token, that will be "minted" with specific local state on a per token-basis while this state can change over time through the execution of a method in the smart ...
2
votes
1answer
289 views

Why public variables aren't able to implement interface functions?

I'm curious why interfaces don't accept public variables as implementations, since public variables have getter functions generated for them. For example why couldn't the ERC20 balanceOf interface ...
1
vote
1answer
101 views

Why standard tokens manually create getters for balanceOf and totalSupply [duplicate]

I've been reading through different implementations of ERC20 tokens and I noticed that many of them define balanceOf[address] as balances[address] and then create a public getter() to match the ...
0
votes
2answers
407 views

How do I see the value of a string stored in a private variable? [duplicate]

I have read many times that sensitive data should never be stored in a transaction, but, specifically, how would the value of a state variable be read if marked private?
0
votes
0answers
113 views

How to interact with a smart contract to change a variable state

How do I change a variable in a smartcontract (bool) As requested, a new followup question from the above^ about ethereum smart contracts (solidity) If I have, early in the contract: bool public ...
2
votes
1answer
185 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; ...
1
vote
1answer
96 views

Why would data be passed into a contract constructor rather than just hardcoding it, which would be less costly?

Doesn't it cost more to pass in variable assignment via a constructor due to changing state? Wouldn't it be cheaper to just assign them in the code? I am wondering if there are advantages to using ...
1
vote
1answer
555 views

Why do some variables' names end in underscore?

On Open Zeppelin's ERC20 BasicToken contract the variable totalSupply_ follows a naming convention I haven't seen before. Is that to differentiate it from the function totalSupply() below or is there ...
0
votes
1answer
190 views

Reading variables from web3 (Documentation is out of date)

I'm trying to read an ownersNum public uint from my contract. I instantiate in node: l = console.log; var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); let c = new web3....
0
votes
1answer
375 views

Calling a state-changing function via web3

I am trying to call a function which changes the length of a global storage array. At first I thought that the problem was related to the array-length changing attempt. But I have finally come to ...
0
votes
1answer
52 views

Unable to change the length of a global 2D storage array

I am facing difficulties changing the length of a global 2D storage array. It seems to be working correctly on Remix IDE, but when I try to test it on ganache-cli (formerly known as testrpc) - either ...
1
vote
1answer
34 views

What is the length of an empty fixed sized array?

Let's say we initialize a state variable as: uint[10] public fixed_array; This is a fixed sized array which is currently empty. What would fixed_array.length return? 0 or 10?
1
vote
1answer
333 views

Access previous state

Let's say I have a uint public myvar in my contract that is initialized to some value. Then, myvar gets set to 3 in the next block. How can I retrieve the old value? Is this possible with web3? ...
0
votes
1answer
255 views

I cant get the value of a state variable public

I am developing a smart contract which I have two contracts(A and B). I have an array variable in A and fill it with values but when I get that variable from B, the array address is empty. pragma ...
2
votes
4answers
425 views

Conceptualizing smart contract variables

I'm having trouble figuring out how variables are stored on the block chain. How can a smart contract be immutable and have global variables that can change? Just say I a simple contract like below......
2
votes
2answers
96 views

Is Solidity creating an implicit getter for a nested contract that is created?

Is Solidity creating an implicit getter or not for a nested contract that is created? Example: contract Foo { .... } contract Bar { Foo public foo; Bar() { foo = new Foo(); } ...
3
votes
2answers
1k views

Why is uint so popular

Among every tutorial/real world example I have yet to come across anyone using the int datatype, I almost thought there wasn't one existing.. Is there a specific reason for uint's uncontested ...
7
votes
3answers
4k views

How to get the cost (in gas) of the non-constant function call?

In my understanding, there are some situations, where the compiler can't calculate, how much Gas it takes to complete the function call. The most obvious example - when your function is calling some ...
11
votes
2answers
6k 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 ...
0
votes
0answers
597 views

totalSupply in ERC20Basic contract is not initialized to zero. Does that matter?

I copied code from TenX, which copied code from OpenZeppelin. TenX and OpenZeppelin has this code for contract ERC20Basic: contract ERC20Basic { uint256 public totalSupply; function balanceOf(...
2
votes
1answer
474 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 ...
1
vote
0answers
63 views

Layout of State Variables in Storage -> specifically NON Statically-sized variables e.g. Mapping

The following page provides information on how to access a contract's state variables, regardless of who the owner is or what methods are exposed. http://solidity.readthedocs.io/en/latest/...
1
vote
1answer
112 views

Function doesn't change change variable's value

I have made a contract with a struct, Stock. I have an array with two such Stocks. They can be initialized fine, but when I try to change the value of a variable nothing happens. Also, the same ...
1
vote
2answers
156 views

Not able to read data from smart contracts

I am doing PoC on Ethereum using Azure Ethereum network and Web3. I was working from last 1 month and I have created one smart contract for student management and that was working like fab. But for ...