12

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 { uint storedData; // State variable // ... } Local variables Carries the usual meaning, that their context is within a function and cannot be accessed ...


8

You can get the gas estimations by adding --gas to solc: > solc --gas Test.sol ======= Test.sol:Test ======= Gas estimation: construction: 118 + 70800 = 70918 external: addOwner(address): infinite However, there are many cases when the gas estimator reports infinite gas. It doesn't necessarily mean that there is an infinite loop in your code or ...


5

It's unusual to need negative numbers. If you don't need negative numbers, there is no reason to use an int, and it's (slightly) easier to write secure code for positive numbers if you don't have to worry about what happens if they're negative. (I say "slightly" because in Solidity you still have to worry about uints overflowing.) For most practical ...


5

The answer to your title question (and subsequent assumptions) is no. All variables from a contract are stored in the storage trie which lives under the contract's address. Storage is not given its own Ethereum address. It seems like what you want to do is access specific parts of the contracts storage, which you can do with web3.eth.getStorageAt. Maybe ...


3

I think that it is more easy that constant storage variables are simply put in the compiled code (as in conventional languages with MACROs or CONSTANTS), indeed each occurence and its value is known in advance, so it is possible to put in the compiled code the instruction PUSH <constant-value> whenever is needed. It would cost few gas units, 3 and only ...


3

There's no meaning as far as Solidity is concerned. Some programmers choose to use a leading underscore for all function parameters, just as a convention to indicate that they're function parameters. They're also often used so as to avoid collisions, e.g.: uint256 totalSupply; constructor(uint256 _totalSupply) public { totalSupply = _totalSupply; } ...


3

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 first a = _a will set the array length. And then y.push(2900) will append a new value to the array incrementing its length.


2

I suspect you are talking about the case when the arguments for the constructor are known in advance before deployment. In this case you are right it's more efficient to get rid of the constructor parameters and add them as constants in the code thus potentially eliminating a few state variables and saving on gas. There are cases, however, when it's not ...


2

owners is an array. While push seems to be constant time, and therefore could conceivably have its gas usage calculated exactly, perhaps the compiler just throws up its hands. "Oops. An array. Non-constant gas cost. I better warn the programmer." You can see this in the warning message where it mentions loops. Code that spins through a growing array will ...


2

It can't implement the interface Even though this is a duplicate question, I'm not sure the other answers adequately explain the issue. The problem is easily demonstable with a simple example: Example: pragma solidity ^0.4.21; interface ERC20 { function balanceOf(address) external view returns (uint); function transfer(address, uint) external ...


2

For the example contract you gave, it looks like there's a bytes32 state variable at slot 1 with the value "A very strong secret password :)". I found this by just calling getStorageAt a couple times: > web3.eth.getStorageAt('0x6260319bcbcbf33f84397ae0000e49b0f50ee075', 0, (e, v) => console.log(v)) ...


2

All public variables generate a getter with the same name as the variable. So a variable with name data will result in a function with signature function data(). Therefore, if you want, you can calculate the call signature with the formula you provided.


2

See issue #1174 in their openzeppelin-contracts repo. "Solidity adds public getters to public state variables. This is kind of magical and dark, and could lead to mistakes. We should be more explicit on everything we do, to make the code clearer and easier to review. So let's get rid of the automatic getters making all the public state ...


2

Can we get the value of the variable at a particular block number? Yes, for example, using web3.js v1.2.1: const variableValue = await contractInstance.methods.variableName().call(null, blockNumber);


1

why exactly string variable must be memory That's not true. It would be helpful to know what you are reading that gives that impression. This compiles: pragma solidity 0.5.1; contract StringStorage { string[] public str; function push(string memory s) public { str.push(s); } function pop() public view returns(string memory s)...


1

Function onlyOwnerSetBurningRate is not constant (neither pure nor view). As such, you cannot fetch its return-value from an off-chain call (i.e., the return-value is useful only when you call this function inside a contract). So your usage of .call() here is wrong to begin with. After you remove it, token.onlyOwnerSetBurningRate(1234) will return the ...


1

Try following commands after migration. I am using truffle console. SaveData.deployed().then((instance) => instance.setSalary(1000)) SaveData.deployed().then((instance) => instance.getSalary()) and its working for me.


1

Why using IPFS if you want to keep your content private and restricted to your backend middleware only ? Just use a normal database with access control. IPFS is meant to distribute and share public content efficiently across a peer2p network. Second point in term of feasibility, you need to consider that publishing an IPNS takes currently a very long time (...


1

The Ethereum blockchain is a state machine. When you define a state variable in a submitted transaction that data is stored and synchronised across the nodes of the network. For example “x is ‘hello’” When you submit a transaction making a change to that variable you essentially store a message that “x is now ‘goodbye’.” This is synchronised across the ...


1

spin() is marked constant (a deprecated alias for view). So it can't change any state. When you call a view function, instead of sending a transaction to the network, you just ask one node (the one you're connected to) to run the code and tell you the result. No changes are persisted or stored in the blockchain. If you remove constant, you'll send a ...


1

solc will generate the ABI for you (as will remix and truffle) Just run solc --abi yourfile.sol. You can see a list of compiler options here.


1

You should simply include those variables outside of the constructor function as a global variable for the contract. Take a look at a pretty simple to understand, and very commonly used ownable contract: https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/ownership/Ownable.sol contract Ownable { address public owner; event ...


1

Mostly, it's for two main reasons: 1) Functions aren't variables and they are not interchangeable 2) Functions support a lot more things than variables do. Actually variables don't support any functionality, just their (convenience) getters. Functions and variables behave quite differently. You have to implement the interface's functions, which literally ...


1

EDIT: I think my answer here is incorrect. It is memory that gets quadratically more expensive. I've left the answer below unedited. I think this is because owners.push(newOwner) expands storage usage each time you call it. Storage gets exponentially more expensive the more you use. So this function will be cheap if there are 0 owners, and will get more and ...


1

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 the rest: function arguments and variables declared within functions scope. as you know Each method has its own entirely new scope. Per design, states as ...


1

Your contract code works fine: your variable count is public anyways. you can just try using the automatic getter SimpleTestInstance.count() my guess the problem you had was with uint and int. Remember that int or uint stands for uint256 and int256. So depending on the type signatures of your contracts, it may be wrong. link to fiddle: https://ethfiddle....


1

It sounds like a compiler error (I have no idea what is "formal verification section"). Most likely Solidity compiler has been upgraded to a newer version that comes with stricter checks. However it is impossible to tell unless you include your contract source code and actual errors in the question. Please edit the question and use Markdown code ...


1

Yes that is precisely why. If totalSupply_ was named totalSupply it would clash with the function totalSupply() and you would get the following error message: DeclarationError: Identifier already declared.


1

Using web3js, you need to pass the options in the call function and use a promise or a callback to handle the response, for exemple: contract.methods.buyKey().call({from: 0x, <somemore params if required>}, function(error, result){ if(error) { do stuff } else { //your result is the result variable } }) With a promise: ...


1

module in the question's code will always only make "calls". If you want to change state, you must make a transaction. In web3.py, that looks like: mycontract = contract(address) mycontract.transact({... your transaction parameters ...}).setLength(1) Then, after waiting for the transaction to be mined, getLength() will retrieve the new value.


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