Failure Timestamp too far in future, Nem-sdk

Trying to sign a transaction using nem-sdk but getting the error, timestamp too far in future, when i tested it initially it worked for me, but now continuously getting this error. I go through the code in nem-sdk and here is the code written to calculate timestamp

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

let createNEMTimeStamp = function() {
return Math.floor((Date.now() / 1000) - (NEM_EPOCH / 1000));
}
which returns Monday, February 5, 1973 11:20:35 AM GMT+05:00

i checked network sync time it was Sun, 14 Apr 5067 19:50:19 GMT

Please check if your operatin system time is synced. Unfortunatelly new nem-sdk takes your local time (Date.now()) instead time from node.
I reported this issue here: https://github.com/NemProject/NanoWallet/issues/490

i checked, my os time is synced but i didn’t got that point why network time is giving me timestamp of 5067, it should not be greater than 2018. And nem sdk is giving time of 1973… Can’t i sign a transaction independently without using nem-sdk? How can i calculate the timestamp without nem-sdk? Let suppose i dont want to use any sdk, library whatsoever… How can i calculate the timestamp?

Waiting for response!!!

What node are you using?
Your value should be around:
http://hugealice.nem.ninja:7890/time-sync/network-time (field receiveTimeStamp)
When I writing this is 97868651590. So it should be sent 97868651590/1000 in timestamp field.
When you calculating from Math.floor((Date.now() / 1000) - (NEM_EPOCH / 1000)); it returns similar value.

Could you write what values you sending?

Couple solutions:
Three possible solutions/workarounds.

  1. switch to node nistest.opening-line.jp. It uses different configuration so should allow wrong timestamp.
  2. change your local time -30sec
  3. use fix from here https://pastebin.com/HqcDeaEC (overriding timestamp in Line 29-33)
  4. of course fix nem-sdk to use time from node (sth similar to point 3)

Hi @CryptoBeliever, I’m currently trying to create a transferTransaction using NEM-SDK (npm package) in Javascript.
let common = nem.model.objects.create(“common”)("", privateKeyDecr);
// Create an un-prepared transfer transaction object
let transferTransaction = nem.model.objects.create(“transferTransaction”)(
to,
amount,
“”
);
// Prepare the transfer transaction object
let transactionEntity = nem.model.transactions.prepare(“transferTransaction”)(common, transferTransaction, nem.model.network.data.testnet.id);
// Serialize transfer transaction and announce
nem.model.transactions
.send(common, transactionEntity, endpoint)
.then(res => {
console.log(res);
const data = {
code: res.message,
txHash: res.transactionHash.data
};
resolve(data);//returning the transactionID as a promise to another function
})
.catch(err => {
reject(err);
});

If I attempt to execute this function continuously I get the error message that the timestamp is too far in the future, I’ve gone through almost all of your comments and discussions regarding this issue on forums and other sites on the net. You suggested using the /time-sync/network-time, I’m currently publishing transactions on the testnet using the timestamp value from the url http://23.228.67.85:7890/time-sync/network-time/ for testnet. But still it gives me the same “FAILURE_TIMESTAMP_TOO_FAR_IN_FUTURE” error and its not going. Kindly suggest what should I do?
Could you also suggest how can I create transferTransactions using RequestPrepareAnnounce using a public node (like [http://hugealice.nem.ninja:7890], for mainnet and http://23.228.67.85:7890/ for testnet)? or should I not use RequestPrepareAnnounce at all?

@codehard-achal prepare announce is not good choose because you sending private key via network. It should be used only on local nodes.

Did you looked at my code? https://pastebin.com/HqcDeaEC
I’m setting there time from node.