Questions tagged [view]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
0 answers
104 views

#Wagmi: TypeError: x.replace is not a function after migration from 0.X to 1.X.X

Same code I didn't change a thing. Only a few things in wagconfig to make the migration but the rest should work. I have this error using: const { config, error } = usePrepareContractWrite({...data}) ...
Mentasuave01's user avatar
1 vote
2 answers
32 views

Call mutating function within view function

I would like to implement a process similar to what Nick Johnson wrote about some years ago. https://weka.medium.com/dividend-bearing-tokens-on-ethereum-42d01c710657 I'm using 0.8.19 and changing the ...
Rob Hitchens's user avatar
  • 54.7k
2 votes
1 answer
21 views

SOLIDITY NOOB QUESTION. Is it necessary to specify that a function is a view function if it's obviously a view function?

For example: function contains(address _key) public view returns (bool) { return map[_key] != 0; } I don't know how this could be manipulated to change the state of anything, so to me it ...
Paul DeLucia's user avatar
5 votes
2 answers
433 views

Preserving visibility "view" of a method using delegate call to a view method

I am using a delegate call inside a view function to a view function in the implementation contract The compiler throws an error meaning that the delegate call can change the state, therefore, can not ...
donoso.eth's user avatar
  • 1,383
0 votes
1 answer
42 views

How can I write a `view/getter` function to see the results of another function

This is my code to remove an element from an array using "shifting method" : // SPDX-License-Identifier: MIT pragma solidity 0.8.7; contract Arrayelement{ //context : /* let an ...
shikamaru's user avatar
0 votes
0 answers
84 views

Reading View Function with ethers.js returns error

I have the following code to read a function for a contract deployed on mainnet. const fetch = require('node-fetch'); const response = await fetch('https://api.etherscan.io/api?module=contract&...
Joby Ingram-Dodd's user avatar
1 vote
1 answer
199 views

Function cannot be declared as view because this expression (potentially) modifies the state

Compiling the contract returns this error. TypeError: Function cannot be declared as view because this expression (potentially) modifies the state. --> contracts/certification/token/...
Sky's user avatar
  • 2,204
2 votes
2 answers
169 views

What happens if a view function has gas cost above the block gas limit?

One of my projects has a complex view function that loops through arrays, maps etc. It doesn't spend gas, but I am afraid one day its estimated gas cost might exceed the block gas limit, and I ...
Sky's user avatar
  • 2,204
2 votes
0 answers
38 views

Silence error: State-changing modifier on a view function

In the past it was possible to use state-changing modifiers on view and pure functions. It was very useful when used properly because one could work out what the state would be and will be when the ...
Rob Hitchens's user avatar
  • 54.7k
0 votes
1 answer
111 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 ...
MrFrenzoid's user avatar
3 votes
1 answer
211 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; ...
Lauri Peltonen's user avatar
0 votes
1 answer
32 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; ...
Goro's user avatar
  • 1
0 votes
2 answers
341 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 ...
Andreas Tzionis's user avatar
2 votes
0 answers
117 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 ...
Gregory Magarshak's user avatar
0 votes
1 answer
92 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?
Elijah Muraoka's user avatar
0 votes
1 answer
80 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 ...
tythereum's user avatar
1 vote
2 answers
111 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 ...
CasualScience's user avatar
3 votes
1 answer
160 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 ?
user87577's user avatar
0 votes
0 answers
545 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 ...
pdmoerman's user avatar
  • 131
0 votes
1 answer
772 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{...
Andreas Dilaveris's user avatar
1 vote
1 answer
84 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? ...
Ehsan Khodarahmi's user avatar
0 votes
2 answers
806 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 ...
Damir Olejar's user avatar
0 votes
0 answers
23 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 ...
Hemant Srivastava's user avatar
1 vote
3 answers
457 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 ...
porton's user avatar
  • 1,744
1 vote
1 answer
191 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?
Кирилл Волков's user avatar
1 vote
2 answers
122 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 ...
alfo888_ibg's user avatar
0 votes
1 answer
154 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 ...
Tabish Mir's 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 ...
Abhishek Mishra's user avatar
2 votes
1 answer
83 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 ...
Kevin Wad's user avatar
  • 317
5 votes
3 answers
2k 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 ...
pan1994's user avatar
  • 169
5 votes
2 answers
4k 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, ...
Dr Lee A. Christie's user avatar
0 votes
1 answer
40 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() ...
GraphicalDot's user avatar
6 votes
2 answers
755 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) { ...
UnexpectedCharacter's user avatar
0 votes
0 answers
79 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 ...
Robert Oschler's user avatar
1 vote
4 answers
4k 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 ...
Lomo's user avatar
  • 103
3 votes
2 answers
3k 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 ...
Iulian's user avatar
  • 640
0 votes
2 answers
2k 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.
Susan's user avatar
  • 11
1 vote
1 answer
3k 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 ...
Ashwinkumar Suryavanshi's user avatar
3 votes
1 answer
349 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 ...
Sebastien's user avatar
  • 323
2 votes
1 answer
2k 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 ...
matthias_buehlmann's user avatar
3 votes
2 answers
883 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 ...
D.Rek's user avatar
  • 131
3 votes
1 answer
208 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 ...
Jesbus's user avatar
  • 10.3k
21 votes
2 answers
12k 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 ...
Mustafa Caglar's user avatar
0 votes
1 answer
57 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 ...
Robert Oschler's user avatar
11 votes
2 answers
7k 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 ...
rollotommasi's user avatar
2 votes
3 answers
792 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; } ...
Kronos's user avatar
  • 896
1 vote
3 answers
1k 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 ...
Nachiket tapas's user avatar
0 votes
2 answers
413 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 ...
Gnaaaa's user avatar
  • 3
0 votes
1 answer
749 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? ...
alper's user avatar
  • 8,368
2 votes
1 answer
3k 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 ...
Kuelf Deez's user avatar