Timekeeping in smart contracts

  1. I call a smart contract and pass and argument which represents unix time as Uint64 argument.
  2. Inside I compare this against the current time (using Global.latest_timestamp() in PyTeal), so it looks like the TEAL assembler can infer that my argument is representing time.
  3. When I call getApplicationByID, inside the return value (app.params[‘global-state’] element containing { key: mytime, value: } I get an uint surprisingly contatning the estimated block number instead of the unix time that I put in.

Can someone confirm that the Algorand VM is converting this, or am I making a mistake somewhere?

Thanks,
Jordan

  1. Inside I compare this against the current time (using Global.latest_timestamp() in PyTeal), so it looks like the TEAL assembler can infer that my argument is representing time.

This function returns a uint64, so there is no inferring of what it represents. Just numeric comparison.

  1. When I call getApplicationByID, inside the return value (app.params[‘global-state’] element containing { key: mytime, value: } I get an uint surprisingly contatning the estimated block number instead of the unix time that I put in .

I don’t quite understand this. You’re making this call off chain and you see a value that looks like round instead of the timestamp you’re expecting?

There should be no magic conversions happening in the AVM. If the value you’re getting back is indeed a round number not a timestamp, double check that the thing writing to it is 1) actually writing to that key, 2) writing the argument you’re passing.

Ben

@Ben, please ignore. I was introspecting an old version of my contract, left on-chain as I forgot to destroy it.

Thank you anyway - you reaffirmed that this was impossible and that I should check it more stubbornly.

1 Like