0
// SPDX-License-Identifier:MIT

pragma solidity ^0.8.7;

contract Try{

    uint public deployedTime;

    constructor(){

        deployedTime = block.timestamp;

    }
    
    function getPassedTime() public view returns(uint256){
        return block.timestamp - deployedTime;

    }
    
}

I tried to get passed time from contract's deployed time. For doing this i used block.timestamp' but it is the time where block is mined. This makes getPassedTime function not like 1,2,3 which is real passed time, but it only gives when block is mined.Is there any way for getting real passed time in solidity.

1
  • The only valid time is when the block is mined. Anything else is arbitrary.
    – 0xSanson
    Aug 26, 2022 at 11:17

1 Answer 1

0

If 'getting real passed time' means the seconds elapsed from the moment you click the deploy button to the moment you call the getPassedTime() function, then I don't think there is anyway to achieve this.

Any kind of transactions including the contract deployment made to the Ethereum depends hardly on the network congestion so the moment you click the deploy button isn't necessarily equal to the moment the deploy transaction is mined into a block.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.