Questions tagged [state-variable]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
0answers
8 views

Burn a token relatively to another's contract variable

I have a contract deployed with a variable that increases everytime a new transaction is made. I would like to create a token with some burn depending on the variable value. For example I would like ...
0
votes
0answers
18 views

The data type of the return value of the solidity function has changed

As you can see, I have designed a struct in the solidity.There is a function in the solidity with the return value type User mapping(address => User) public _userInfoMap; struct User{ uint ...
1
vote
1answer
49 views

How to protect your state variables from getting modified?

from what I understood, any state variables that are not private can be called and modified by any contract that inherets the parent contract. it usually takes more than one contract to develope a ...
0
votes
0answers
31 views

Does delegatecall() use only the calling function?

Let me explain with the code: contract A { function f() public { [...] g(); } function g() private { [...] } } contract B { A a; function delegateA() public { (bool success, ) = address(...
2
votes
1answer
20 views

Difference in cost between external contract as state variable vs. instantiation of contract?

For pragma solidity ^0.6.0; interface ExternalContract { function initialize() external; } contract Test { ExternalContract c; constructor(address externalContractAddress) public { ...
2
votes
1answer
80 views

Gas cost of setting a state-variable to the same value

According to this spec, setting a state-variable to the same value consumes 200 gas. However, I conducted a test over ganache-core v2.10.2, and the result was closer to 800 gas: Solidity Contract: ...
2
votes
1answer
876 views

Member “push” not found or not visible after argument-dependent lookup in address[] storage ref

I am failing to use the push method against a dynamic array declared as a state variable. How can I do this? I declare a dynamic array of addresses as a state variable like below: contract Sample { ...
5
votes
2answers
208 views

How to call a method after a specific tx in a block

With web3, it is possible to call a method of a smart contract at a specific block : myContract.methods.methodName().call(transactionObject, blockNumber, callback) Is there a way to call it after a ...
0
votes
0answers
26 views

Maximum Number of State Variables

My Solidity linter warns me if I have more than 15 variables declared, and I got around this by packing multivariable into an array, such as changing unit public x1; unit public x2; into unit[2] ...
1
vote
1answer
73 views

How to find value of non-public state variable

I understand that public state variables automatically creates a getter function when deployed, its value can be accessed via the getter function. However, if a state variable is not public, how can ...
1
vote
2answers
275 views

Getter function for public variables

Many token contracts have unrestricted getter functions for state variables, which seems redundant (eg, see OpenZepplin's ERC20 contract). For example, a contract could have it this way: uint private ...
0
votes
1answer
40 views

Accessing dynamic variable name - external contract

Contract A wants to call an external contract B/C/D/E/F but the variable name is different within each contract B/C/D/E/F, and contract A does not know the variable name for B/C/D/E/F at the start. ---...
0
votes
1answer
38 views

What if millions of records to be fetched from blockchain?

This is just a hypothetical scenario. Let's suppose someone saved million of information in blockchain with huge gas consumption so far. As for reading data in ethereum smart-contract cost no gas. ...
0
votes
0answers
18 views

The code is not returning the value of x? [duplicate]

pragma solidity >=0.5.0 <0.7.0; contract Example{ uint256 public x=3; function setArr(uint256 y) public returns(uint256){ x=y; return getArr(x); } function getArr(...
1
vote
1answer
62 views

State Variables: What are they and how to create them?

I am new to ethereum and Solidity. I thought state variables are supposed to retain their value between calls. In the Solidity documentation, in the section State Variables, it says that state ...
0
votes
0answers
44 views

if “address public x = tx.origin”, why does “require (tx.origin == x”) work and "require (tx.origin==tx.origin) not

Below is a contract that i have commented on, hoping to understand the logic of the arguments. Below in bold is the question in question. The .sol currently works fine. pragma solidity ^0.5.11; ...
1
vote
1answer
51 views

Receiving error while getting state variable value after using selfdestruct method “Error: Returned values aren't valid, did it run Out of Gas?”

I am using selfdestruct method and passing the payable address to it but receiving the following error when trying to get the value of a state variable : "Error: Returned values aren't valid, did it ...
11
votes
1answer
2k views

What is the immutable keyword in Solidity?

What is the immutable keyword in Solidity and how do I use it?
0
votes
3answers
61 views

Length of state array is not changeable in Solidity

Consider there are 3 contracts: BankA, customer, and BankB.BankA transfers some ethers to customer and after that some customer's state variables must be changed (in a better words be updated). It ...
0
votes
1answer
41 views

How Solidity field variable update is happening?

I am curious to know about, how the updation of field variables in solidity is happening ?. Whether world state is maintaining for each variable in the contract as like account balance?. And one more ...
1
vote
1answer
58 views

Why OpenZepplin always use private visibility for state variables?

Why OpenZepplin always use private visibility with getter functions for its state variables? I can't find a reason why they are not using public, is there any potential security or gas cost difference ...
1
vote
0answers
38 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
588 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
253 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 ...
1
vote
2answers
273 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
36 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 ...
2
votes
2answers
420 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
54 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
203 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 ...
3
votes
1answer
759 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
161 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
69 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 ...
5
votes
1answer
424 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
18 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
260 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 ...
4
votes
1answer
2k 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
31 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
571 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
55 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 ...
3
votes
1answer
824 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
134 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 ...
3
votes
2answers
2k 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
215 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
338 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
120 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
992 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
378 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
487 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
68 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
37 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?