0

I expected to be able to print out the time in a contract but...

print(current_time());

didn't get compiled and I get the error "use of undeclared identifier 'current_time'"

1

Time is treated in a special way inside the blockchain. The main reason for the limitation is that the blockchain data needs to be consistent and reproducible so playback of the blockchain reaches the same state.

This should work:

print(now());
  • Ami, when I compile im getting an error error: use of undeclared identifier 'now'; did you mean 'new'? print(now()); – Bill Jul 8 at 2:57
  • What version are you using for the eosio.cdt? – Ami Heines Jul 8 at 4:13
  • if i run cleos version client i get Build version: 448287d5 – Bill Jul 8 at 4:25
  • What version of the eosio.cdt? Try this: >> eosio-cpp --version – Ami Heines Jul 8 at 4:59
  • eosio-cpp --version eosio-cpp version 1.6.1 but i did just run brew upgrade eosio – Bill Jul 8 at 5:10
1

In more recent version of eosio.cdt, now(), which used to return the seconds since the beginning of the unix epoch, has been removed.

The new way of doing this would be:

#include <eosio/system.hpp>

print(current_time_point().sec_since_epoch());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.