Here is my getLatestPrice( ) function within my smart contract:
function getLatestPrice() public view returns (int256) {
(
,
/*uint80 roundID*/
int256 price,
,
,
) = priceFeed.latestRoundData(); /*uint80 answeredInRound*/ /*uint timeStamp*/ /*uint startedAt*/
return price;
}
This function has been implemented strictly, as the Chainlink documentation suggests.
Now here are my questions:
Why do I run into errors whenever I want to add a small logic to this function? For instance, when I try to assign the retrieved response, named price, to one of my local variables, the assignation does not get completed, and my local variable stays zero, although they are the same type ( int256 )
On the other hand, after witnessing the above errors, I tried to implement the logic another way. However, it seems I cannot do something like the function below. Can someone clarify the situation for me?
Here is the function:
function calculateDong() public returns (int256) {
myvariable = int256(getLatestPrice());
return myvariable;
}
To make it more clear, here is a screenshot of the two mentioned functions within my script:
And here are the return values we see after calling them in order. Why the second one shows zero?


dongis not defined, right? – Markus Schick Aug 28 '22 at 09:07state modifyingthen. see: https://ethereum.stackexchange.com/questions/6380/how-to-get-values-returned-by-non-constant-transaction-functions – Markus Schick Aug 28 '22 at 12:42