fbpx

Testing dates in Solidity smart contracts – Part I

Julien Klepatch

Dates are a bit weird in Solidity. Solidity does have some keywords for working with dates, like now, or 1 day, but it does not have a native date type. Instead, dates are represented as integers, using timestamps in seconds.

In our Truffle tests, we need to be able to pass dates to Solidity smart contracts in order to test them. However, when you create a date in Javascript, you get a Javascript object, not a timestamp, and there are no functions to convert a Javascript date object to a timestamp in seconds. How can we work around that?

In this video, you are going to learn how to pass Javascript dates to Solidity smart contracts in your Truffle tests.

0 Comments

Leave a Reply

More great articles

How To Use Ganache GUI With Truffle? | Episode 14

https://www.youtube.com/watch?v=aRJA1r1Gwu0&t=1s Ganache CLI is an Ethereum client used for developing smart contracts and dapps. It is a command-line tool but…

Read Story

Loan state machine in Solidity

In this video we will create a loan smart contract with Solidity. There will be 2 kind of parties interacting…

Read Story

Never miss a minute

Get great content to your inbox every week. No spam.
[contact-form-7 id="6" title="Footer CTA Subscribe Form"]
Arrow-up