How can I use dynamic variables work in Ethereum? #2101
-
Hey devs, // SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
contract SetCurrentTimeContract{
uint public currentTime;
function setCurrentTime() external{
currentTime = block.timestamp;
}
} Suppose I have this smart contract, which sets the state variable currentTime to the current timestamp. @PatrickAlphaC |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
@deeptshukla This is what will happen with this. After deploying the smart contract, whenever you call this function, it will get the timestamp of the latest block mined and assign it to this variable. But if you are talking about automatically updating this variable then for that you need to use Oracle. |
Beta Was this translation helpful? Give feedback.
-
@alymurtazamemon 's answer is spot-on about the functionality. Answering the other part: well, that is precisely what oracles do. In this case it is a simple one-liner, but when there are way multiple factors affecting the trustworthiness of the contract people will not trust a random contract. And oracles can do the same whilst being non-permissible as well as maintaining trust; of course, prominent oracles and not shady ones. |
Beta Was this translation helpful? Give feedback.
-
Thanks @alymurtazamemon and @krakxn for the explanation. |
Beta Was this translation helpful? Give feedback.
@deeptshukla This is what will happen with this. After deploying the smart contract, whenever you call this function, it will get the timestamp of the latest block mined and assign it to this variable. But if you are talking about automatically updating this variable then for that you need to use Oracle.