Questions tagged [view]

The tag has no usage guidance.

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

Why the function needs payable() in solidity?

In my solidity code, I am not using the global variable msg.* but still I get the error message in the function. Please explain why this function needs to be a Payable function The below snippet is ...
2
votes
3answers
77 views

Should I use require in view functions?

When I call a solidity function to get a struct element, is it a best practice to use require and check if the element exists or should I just return the empty values? Without require: function ...
1
vote
0answers
42 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, ...
0
votes
1answer
18 views

Why this function doesnt need Gas for execution?

pragma solidity ^0.4.17; contract Lottery{ address public manager; address[] public players; function Lottery() public { manager = msg.sender; } function enter() ...
5
votes
2answers
162 views

Return the struct inside array inside array

pragma solidity >= 0.4.25 < 0.6; contract Bank { struct Customer { uint age; } Customer[][] customers; function foo() public { if (customers.length > 0) { ...
0
votes
0answers
46 views

Controlling access to functions with VIEW visibility with signed transactions?

Controlling access to functions that require ETH is straight forward because you get an address you can trust because it has been signed and verified, and therefore upi can use for access control ...
0
votes
3answers
300 views

Gas cost call vs send for pure/view functions

I'm aware of the fact that pure/view functions cost no gas with a simple "call". But what happens if i have a function that changes the contract state based on the pure/view function result. Do i have ...
0
votes
2answers
296 views

Gas for view functions

I read in many places that view functions do not cost gas however that's not true because they cost gas for blockchain operations even if those do not change the state. Correct me if I am wrong For ...
0
votes
2answers
151 views

what is the difference between payable and view in a smart contract in solidity?

I don't quite understand the concept of payable in a function in the smart contract and the difference between payable ,view and pure.
1
vote
1answer
502 views

Calculator Smart Contract [duplicate]

Below is my smart contract code for calculator. pragma solidity 0.4.24; contract Calculator{ uint result=10; function Calculator() public { } function getResult() public view ...
2
votes
1answer
100 views

Is it possible to access block.number inside a view function?

I have a transactional function that can only be called every few blocks, and I would like to create a view function that returns the number of blocks until the transactional function can be called ...
1
vote
1answer
68 views

What happens if view function calls function that is neither 'view' nor 'pure'?

currently view is not enforced. Calling a function that is neither 'view' nor 'pure' from within a function that is causes a warning, but compiles. My question is what is the result from externally ...
2
votes
1answer
72 views

Call a view function of an Ethereum Smart Contract using a program written in C

my attempt is to call a view function to reatrieve some data from a contract on the Blockchain using a C program. I do have the interface of the contract. I think i need to performe two things in ...
2
votes
1answer
115 views

In Solidity, how to check whether the code is being executed on-chain or not?

I would like to write an external view function that throws when being executed on-chain, but does not throw when executing client-side. (for example when it is called through web3.js) Is there a way ...
5
votes
2answers
1k views

View/Pure Gas usage - Cost gas if called internally by another function?

I know similar questions have been asked before however I could not find an good explanation for the following, In one of the tutorial it says: Pure and View functions don't cost any gas to call ...
0
votes
1answer
31 views

Solidity says my function can by marked as view but my code changes state?

Given the code below, when I compile the code with Remix it says the function processBandPayments() can be marked as view. This concerns me greatly since in my mind, the code is changing state by ...
0
votes
1answer
645 views

Does view functions cost gas? And how to send transaction in a proper way?

I have a method defined as: getNames() view public , if i call on it contractInstance.getNames.estimatedGas() it returns me a non-zero value, why? I mean, view methods should not consume any gas! On ...
2
votes
3answers
271 views

Why cannot I get uint returns without 'view' modifier?

I have very simple contract as.. contract myContract { function foo() public returns(uint) { return 10; } function foo1() public view returns(uint) { return 10; } ...
1
vote
3answers
294 views

Emit event in view function or

Is it possible to emit event in view function (via event or logi)? Or is it possible to return value to javascript without(before) mining in a transaction function? My aim is to avoid wait due to ...
0
votes
2answers
75 views

Which parts of function are executed externally and which are executed “on chain”?

I am still a solidity noob, so I apologize if the question is too basic. I am trying to write a contract which saves the hash of a (potentially) large bunch of data on chain. For this reason, I ...
0
votes
1answer
212 views

Is it possible to send a secret message to a specific Ethereum Address using a smart contract? [duplicate]

I have a secret message that I want to share it with a specific Ethereum Address using a smart contract and I want no one else to see it except that specific Ethereum address user. Is it possible? ...
2
votes
1answer
743 views

Remix error : Function declared as view but this potentially modifies state

This code is inside a view function and gives the error : Function declared as view but this potentially modifies state. if ( auction.iS == false){ //check if such auction exists emit ...
0
votes
2answers
113 views

Is it safe to remove the “view” modifier from the function “getTokenAmount” in the OpenZeppelin crowdsale contract?

This function from the openzeppelin crowdsale sample is marked view as seen here: // Override this method to have a way to add business logic to your crowdsale when buying function getTokenAmount(...
1
vote
1answer
626 views

negative numbers passed to view functions are treated differently to negative numbers passed to transaction functions

Using solidity 0.4.18 I have the following contract: contract MyContact { mapping(address => uint) private balances; modifier positiveNumber(uint number) { require(number > 0);...
26
votes
4answers
18k 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 ...
60
votes
2answers
20k 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 ...