# Informational Vulnerability 5: Transition from now to block.timestamp

{% hint style="info" %}
[**Book an audit with Zokyo**](https://www.zokyo.io/)
{% endhint %}

**Introduction:** Solidity, like any programming language, evolves over time, introducing new features, optimizations, and deprecating outdated syntax or elements. One such deprecation in recent versions of Solidity is the keyword `now`, traditionally used to refer to the current block timestamp. Developers are advised to use `block.timestamp` instead. This tutorial aims to guide you through updating your contracts to adapt to this change, ensuring they remain current, robust, and compliant with best practices.

***

**Concepts**:

* **`now` Keyword**: Previously used to obtain the current block’s timestamp.
* **`block.timestamp`**: The preferred way to access the current block’s timestamp in more recent versions of Solidity.

***

**Why Transition from `now` to `block.timestamp`?**:

* **Clarity**: `block.timestamp` is more explicit and clarifies where the timestamp is coming from.
* **Up-to-Date Practices**: Keeping code updated with the latest syntax ensures compatibility and adoption of the latest best practices.

***

**How to Make the Transition**:

1. **Code Update**:
   * Replace instances of `now` with `block.timestamp` in your contracts.
2. **Testing**:
   * Ensure that your contract’s functionality remains consistent after the update.
   * Run your regular suite of tests to verify that no unexpected behaviors have been introduced.

***

**Practical Example**:

*Before (Using `now`)*:

```solidity
solidityCopy codepragma solidity ^0.7.0;

contract TimeBasedContract {
    uint256 public lastUpdated;

    function update() public {
        lastUpdated = now;
    }
}
```

*After (Using `block.timestamp`)*:

```solidity
solidityCopy codepragma solidity ^0.7.0;

contract TimeBasedContract {
    uint256 public lastUpdated;

    function update() public {
        lastUpdated = block.timestamp;
    }
}
```

In the revised contract, instances of `now` have been updated to `block.timestamp`, aligning the contract with the latest Solidity best practices.

***

**Conclusion**: Transitioning from deprecated syntax to current recommendations, like updating `now` to `block.timestamp`, is a fundamental practice to maintain the health, reliability, and clarity of your smart contracts. Regularly updating your syntax as per the latest Solidity documentation ensures that your contracts remain robust, secure, and efficient.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://zokyo-auditing-tutorials.gitbook.io/zokyo-informational-vulnerabilities/tutorials/informational-vulnerability-5-transition-from-now-to-block.timestamp.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
