How to measure time inside a smart contract

I want to be able to measure time inside a smart contract. Specifically, I want to execute a subroutine once a month (exactly 30 days). How can this be done?

Smart contracts are only executed when an application call is made.
They cannot be “scheduled”.
(To my knowledge, this is a limitation of all the main blockchains.)

However, you can write the smart contract such that anyone can call it once every 30 days.
Then you should have an external script calling it once every 30 days.

In the smart contract, consider using the global field LatestTimestamp. See Transaction Execution Approval Language (TEAL) - Algorand Developer Portal

2 Likes