QuantumMechanics / NEM-sdk

NEM Developer Kit for Node.js and the browser
MIT License
137 stars 82 forks source link

Timestamp too far in future. #42

Open zeshanvirk opened 6 years ago

zeshanvirk commented 6 years ago

I tried to create a transaction, and initially it worked for me, but now i'm getting an error of timestamp too far in future, i go through the code and here is the code written in it to calc the 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)); }

I checked the network time using endpoint /time-sync/network-time and i got timestamp of 5067 that is difficult to understand

{ "sendTimeStamp": 97753111765, "receiveTimeStamp": 97753111765 }

fsanano commented 6 years ago

Hi @zeshanvirk I used moment.js and time is normal:

const nemEpoch = Date.UTC(2015, 2, 29, 0, 6, 25, 0);
const date = moment(nemEpoch + (txTimestamp * 1000)).format('DD.MM.YY HH:mm');
xiewenlong1202 commented 5 years ago

I also meet the same issue, did you solve it? or, where can I find help?

hunternga commented 5 years ago

The same issue happened me while using node and javascript, can anyone fix it or give some alternative solution.

xiewenlong1202 commented 5 years ago

Hi, there. I have solve this problem by sleeping for a few seconds after sign the transaction but before it been send. I think it is because the timestamp is in the future about 24 hour, and if there is no sleep, the timestamp maybe more than 24 hour by 1 or 2 seconds anyway, just try to sleep for a while before you send the transaction to the chain.

HankRobot commented 5 years ago

Yup, I tried it with this code and it works perfectly // Create the apostille var apostille = nem.model.apostille.create(common, "Test.txt", fileContent, "Test Apostille", nem.model.apostille.hashing["SHA256"], false, "", true, nem.model.network.data.testnet.id); //execute transaction 2s later setTimeout(sendtransaction, 2000); //function to call function sendtransaction() { // Serialize transfer transaction and announce nem.model.transactions.send(common, apostille.transaction, endpoint).then(function (res) { // If code >= 2, it's an error if (res.code >= 2) { console.error(res.message); } else { //console.log("\nTransaction: " + res.message); //console.log("\nCreate a file with the fileContent text and name it:\n" + apostille.data.file.name.replace(/.[^/.]+$/, "") + " -- Apostille TX " + res.transactionHash.data + " -- Date DD/MM/YYYY" + "." + apostille.data.file.name.split('.').pop()); //console.log("When transaction is confirmed the file should audit successfully in Nano"); //console.log("\nYou can also take the following hash: " + res.transactionHash.data + " and put it into the audit.js example"); //var var_name_of_file = (apostille.data.file.name.replace(/.[^/.]+$/, "") + " -- Apostille TX " + res.transactionHash.data + " -- Date DD/MM/YYYY" + "." + apostille.data.file.name.split('.').pop()).toString(); var var_name_of_file = (res.transactionHash.data).toString(); console.log(var_name_of_file); var fs = require('fs'); fs.writeFile("C:/Users/User/Desktop/receipt.txt", "Hash: " + res.transactionHash.data + " Content: " + str, function (err) { if (err) return console.log(err); }); } }, function (err) { console.error(err); }); };