Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

Questions tagged [constant]

Constants in programming are definitions whose value is fixed throughout a program's execution. Literals in most languages are constants, for example. In referentially transparent programming styles, all definitions are constant.

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

Memory Efficiency of Constant Variables

Say I have a contract with several functions that apply various particular constants. circumference = 628318 * radius / 1e5; dividend = balance * 123 / 1e4; It would be easier for readers to ...
1
vote
2answers
74 views

Inconsistent Result for Web3 Constant Method Call

Deployed a local private Ethereum environment. While trying to invoke a constant method of a solidity contract getting inconsistent results. Sometimes the result is returned and mostly not. When I ...
1
vote
0answers
57 views

Standard work-around for using a Solidity constant array (which is not supported) in pure function?

I have an array in my contract like this and a pure method which uses it like this (simplified exmaple because my real exmaple is many more lines): uint[16] constant x = [10, 2, 6, 42, 19, 5, 4, 36, ...
2
votes
3answers
98 views

What other constants depend on the current call like msg.sender?

I recently noticed that msg.sender isn't always the original caller's address (see here). It's the address of the current call. So if foo() calls bar(), then msg.sender in bar() will be the address of ...
1
vote
1answer
104 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 ...
0
votes
2answers
340 views

Remix warning - Is constant but potentially should not be.

I am getting the warning on the code shown below. Could you please assist me know to resolve this warning ? warning message - "Is constant but potentially should not be"
1
vote
1answer
88 views

How to get constants value by using Contract name

for example: contract A { uint constant public START_TIME = 10; } import "./A.sol" contract B { function test() public { uint startTime = A.START_TIME; } } If I only need the ...
2
votes
1answer
55 views

Any way to do compile-time computation using rational_const and a constant value?

Of the following three declarations ufixed constant TEST1 = 256; uint constant TEST2 = 256; uint[] testTable1 = [uint(0.001 * TEST1), uint(0.01 * TEST1), uint(1.1 * TEST1)]; uint[] testTable2 = [uint(...
1
vote
1answer
242 views

Constant function returns empty array + web3js

I have a simple solidity script where I tested in remix (injected Web3 using geth local environment) and worked fine returning an array of data from a constant method. pragma solidity ^0.4.11; ...
0
votes
2answers
137 views

Remix shows values from getters only declaring “constant”

pragma solidity ^0.4.0; contract MyFirstContract { uint private age; function setAge(uint newAge) { age = newAge; } function getAge() returns (uint) { return age; ...
1
vote
1answer
638 views

How to properly call getter methods from a specific keypair in web3

In some of my getter methods I'm using msg.sender to deal with access rights. However this just gave me errors, because every single call just comes from the first account of web3.eth.accounts. My ...
2
votes
2answers
191 views

Why does balanceof() return a constant?

The ERC20 token standard specifies balanceof() to return a constant. function balanceOf(address _owner) constant returns (uint256 balance) But the balance amount might change or am I getting ...
29
votes
4answers
20k views

When to use “View” and “Pure” in place of “Constant” [duplicate]

According to the solidity 0.4.17 Release Notes this release finally checks the modifiers view (used to be named constant) and pure on functions. As a rule of thumb, use view if your function ...
0
votes
1answer
45 views

Initiate a transaction from within a constant function

Good day, I know that using a constant function means that no change will be done on the blockchain, but I'd like to have a smart contract that verifies the user input WITHOUT exposing what the input ...
1
vote
1answer
363 views

Why transaction cost for same function differs even though content of function is same?

I have written following contracts to test the gas used by a simple function depends on what parameters. As described here the four use cases, each gives different transaction cost even though content ...
4
votes
1answer
849 views

Overwriting of constant variables by inheritance: Why are parent variables only overwritten in functions of the child?

Let's assume I have the following two contracts Hello and Goodbye, and Goodbye inherits from Hello. Both declare a constant variable aString, i.e. the child contract Goodbye overwrites the parent's ...
63
votes
2answers
21k views

Solidity: What is the difference between `view` and `constant`?

Solidity 0.4.16 introduced the view and constant function modifiers. The documentation says: constant for functions: Same as view. Does this mean view is just an alias for constant? If so, why do ...