Function RETURNS not returning anything without VIEW #436
Replies: 1 comment 3 replies
-
Short answerYour frontend [any code outside of EVM] can get function return values only if a function is declared as Full answerWhen a function does NOT contain On the other hand, functions that DO have Any time your frontend invokes a smart contract function which modifies the state, it will get transaction object as a response, no matter if the function returns a number, or anything. Whatever is the real return value of a such a function is available only to another smart contract which called that function. Or to put it in other words, the return value is not accessible outside of EVM, i.e. in your frontend. The only way for your frontend to access the return value from a function which is not read-only, is to make the function save that response also to the log by emitting an event, and then read from the log. To make it more clear with an example, check out this Chainlink VRF demo I pushed yesterday: https://github.com/bobanm/randomness-logger If you look inside function requestRandomNumbers (uint32 callbackGasLimit) external {
uint requestId = vrfCoordinator.requestRandomWords(KEY_HASH, vrfSubscriptionId, MINIMUM_REQUEST_CONFIRMATIONS, callbackGasLimit, NUM_WORDS);
emit NumberRequested(requestId, block.timestamp, msg.sender);
} If I made this function return const filter = RandomnessLogger.filters.NumberRequested()
filter.fromBlock = CONTRACT_BLOCK_DEPLOYED
const logs = await ethers.provider.getLogs(filter) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
just learned about VIEW function in solidity. I wanted to see if the RETURNS keyword returns something even without VIEW.
this is the code i wrote:
in the image, I called the function funview by passing 10. I can see that the value of b has been correctly calculated as 20, but this was not returned by the function. why is that?
expecting guidance from you.
Beta Was this translation helpful? Give feedback.
All reactions