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

Fomo3D Tutorial

Have you heard of Fomo3D? This is a famous lottery Dapp on Ethereum where the last player to invest in…

Read Story

ERC20 Token Tutorial: Create a custom token in Solidity

ERC20 tokens are a key component of many Ethereum Dapps. They usually represent some sort of ownership over a product,…

Read Story

Rock paper scissors Solidity tutorial

You know Rock paper scissors right? If you don't, that's a simple game where in each round 2 players make…

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