Questions tagged [view]

The tag has no usage guidance.

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

Who pays for the gas used when reading from storage or calling pure / view functions?

I a little confused about this, i've read that pure / view functions don't cost gas / require a transaction when called, other people say that it does cost, but you're not the one pating for it. So ...
user avatar
0 votes
0 answers
12 views

When I call a contract's view function. Where does the code run?

Does it get executed on my browser by metamask with data requested from a node? Or does the node runs it?
user avatar
  • 11
3 votes
1 answer
41 views

Why are local reads so slow?

Why is it so slow to read data from the blockchain? Even if you use a local node, reading is slow. Consider for example the following contract: contract Test { bytes3[100] private largeArray; ...
user avatar
0 votes
1 answer
25 views

return a struct from a mapping of addres-struct

I'm trying to return a struct called Trainer from a mapping of addresses -> Trainer Is there any way to easily retrieve the Trainer struct from the trainersMap? struct Trainer { address owner; ...
user avatar
  • 1
0 votes
2 answers
105 views

View function throws an error with block.number

Looking at https://docs.soliditylang.org/en/v0.8.11/contracts.html#view-functions I understood the solidity view function can work with any function unless it mutate states, emit events or perform any ...
user avatar
0 votes
0 answers
6 views

Function struct array is not returned unless I add view [duplicate]

Contract contract Playground { struct User { bytes32 name; uint256 age; } function getUsersWithView() external view returns (User memory) { return User({name: &...
user avatar
  • 101
1 vote
0 answers
58 views

How to connect wallet / set caller for Read Contract buttons on Etherscan?

When I use the "Read Contract" tab on Etherscan, it works even if I didn't "connect" by Web3 wallet. It seems to be reading the blockchain passively. The thing is, one of the ...
user avatar
0 votes
1 answer
29 views

Viewing an Array in Storage

Let's say Im creating a storage full of people as a person array. Can I retrieve and view all of the people from that storage at once or do I have to view each person separately in Remix?
user avatar
0 votes
1 answer
35 views

What happens if a function that is not defined as a view, doesn't change the data of the contract?

example: function addAllowedTokens(address _token) public onlyOwner { if (!tokenIsAllowed(_token)) { allowedTokens[_token] = true; } } In this code, the allowedTokens ...
user avatar
1 vote
2 answers
72 views

Are pure functions and events verifiable/guaranteed

I am very new to solidity so please forgive me if I'm mistaken, but it seems that pure and view functions are not really run on chain if I access them with web3 (but they are if I access within a ...
user avatar
3 votes
1 answer
89 views

Can I make DDoS attack with view functions?

As I understand the view functions does not require gas. So isn't it possible to spam the network and to overload the nodes with spamming view functions to all the nodes ?
user avatar
0 votes
0 answers
136 views

Return JSON from view function

I'm trying to find the "best practice" to return a JSON formatted string from a view function. Basically, I plan to loop through a set of data stored in contract state, build it all into a ...
user avatar
0 votes
1 answer
177 views

Is calling a view function always free from outside of contract? [duplicate]

In the following generalised code example, would myMethod still be free (no gas cost) to call from outside the contract? Even if it does a series of operations including abi.encodePacked()? contract A{...
user avatar
1 vote
1 answer
74 views

What if running a function longs more than block time?

In a blockchain with a typically small block time such as Polygon (or any other chain in general), what happens if executing of a a) transaction b) view function longs more time than a block time? ...
user avatar
0 votes
2 answers
314 views

How safe are the view functions, can anyone see the data I am sending to a view?

I would like to create a contract that uses the view function, however, I must make sure that nobody can see what data I am sending to a view since it is a sensitive content. The contracts simply acts ...
user avatar
0 votes
0 answers
22 views

How can I store structure items in a variable

I am learning to code in solidity and stuck with view functions. I am trying to return values taken dynamically in a structure using view function. Is there a way to do it is solidity? I tried it but ...
user avatar
1 vote
3 answers
183 views

Do view functions cause reentrancy vulnerabulity?

It's well known that calling an external function before changing something in the contract causes a security problem called "reentrancy vulnerability". Does calling an external function ...
user avatar
  • 1,304
1 vote
1 answer
133 views

Solidity View Function Responce

What does Response for View Function request look like? Does Validator give any prooves that the execution was done correctly?
user avatar
1 vote
2 answers
110 views

Why do I pay fee for reading transaction on Ropsten?

I have a doubt. I am using truffle with meta mask to deploy Smart Contract, write transaction and read transaction on Blockchain. Why do I pay fee for reading data on BlockChain? Should it be free? I ...
user avatar
0 votes
1 answer
106 views

How is data sent to the front-end by a View function?

I am required to send some data from a view-only function to the front-end. I tried using the standard approach by emitting an event with the required fields. However, when the emit call is placed ...
user avatar
4 votes
3 answers
2k views

Smart contract execution without making transaction on ethereum blockchain

If I as a user of a smart contract ,call a function which does a heavy computation but doesn't change anything except the function variables which live only during function execution and then thrown ...
user avatar
2 votes
1 answer
64 views

Getter functions for loop security

Is there any security issue when making for-loops inside getter functions ? Let's say the array is very large, and it takes a long time to loop through the array. Is it a potential threat or I can ...
user avatar
  • 193
2 votes
3 answers
1k 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 ...
user avatar
  • 139
5 votes
2 answers
2k 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, ...
user avatar
0 votes
1 answer
38 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() ...
user avatar
5 votes
2 answers
673 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) { ...
user avatar
0 votes
0 answers
75 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 ...
user avatar
0 votes
4 answers
3k 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 ...
user avatar
  • 93
1 vote
2 answers
2k 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 ...
user avatar
  • 564
0 votes
2 answers
1k 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.
user avatar
  • 11
1 vote
1 answer
2k 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 ...
user avatar
3 votes
1 answer
259 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 ...
user avatar
  • 323
2 votes
1 answer
1k 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 ...
user avatar
3 votes
2 answers
653 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 ...
user avatar
  • 131
3 votes
1 answer
184 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 ...
user avatar
  • 9,037
13 votes
2 answers
9k 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 ...
user avatar
0 votes
1 answer
49 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 ...
user avatar
6 votes
2 answers
5k 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 ...
user avatar
2 votes
3 answers
596 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; } ...
user avatar
  • 866
1 vote
3 answers
676 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 ...
user avatar
0 votes
2 answers
278 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 ...
user avatar
  • 3
0 votes
1 answer
577 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? ...
user avatar
  • 7,689
2 votes
1 answer
2k 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 ...
user avatar
0 votes
2 answers
163 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(...
user avatar
1 vote
1 answer
852 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);...
user avatar
  • 849
47 votes
4 answers
39k 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 ...
user avatar
  • 51.1k
74 votes
2 answers
30k 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 ...
user avatar
  • 8,114