Failure timestamp too far in future rest api [Solved]

i’m trying to initiate transaction via rest api using following code:
var timeStamp = d1.getTime();
var deadline = d1.getTime() + 1000;

var params = {
RequestPrepareAnnounce: {
“transaction”:
{
“timeStamp”: Math.round(timeStamp/1000),
“amount”: 1000000,
“fee”: 500000,
“recipient”: “TAOM33POIATPNENGTRE4VTWVN4W32J3GCZTVG6LF”,
“type”: 257,
“deadline”: Math.round(deadline/1000),

}

but everytime i got FAILURE_TIMESTAMP_TOO_FAR_IN_FUTURE. how to use correct timespan and deadline? i’m using the local time of my computer.

You have to calculate the correct timestamp, taking into account the nem epoch.
Nems epoch started on April first 2015 so that’s where the calculation starts which is a hell of a lot later than for usual unix timestamps. You should look at nano wallet or all the libraries and check what the exact offset is.

var NEM_EPOCH = Date.UTC(2015, 2, 29, 0, 6, 25, 0);

time from server can be fetched using /time-sync/network-time endpoint (is more accurate then local time)

https://nemproject.github.io/#requestPrepareAnnounce
timestamp is number of seconds elapsed since the creation of the nemsis block

Easiest way (but not best because better use timestamp from server and not local computer) is:

var createNEMTimeStamp = function createNEMTimeStamp() {
return Math.floor(Date.now() / 1000 - NEM_EPOCH / 1000);
};

1 Like

Thanks it worked.

1 Like