I am a beginner for Javascript & web3(0.20). I am using Metamask for watching allevents, and I need to get timestamp. I use getBlock.timestamp. Due to Javascript, timestamps are not inorder. I want the timestamp inorder. How do I revise? Thanks a lot.

event.watch(function (error, result) {
    if (!error) {  
        if (result.args.from == user_wallet_address.toLowerCase() || result.args.to == user_wallet_address.toLowerCase()) {
            var blocknum = result.blockNumber;
            **console.log(blocknum);//this is in-order.**

            web3.eth.getBlock(blocknum, function (error, block) {
                **console.log(blocknum);//this is not in-order.**
                if (!error) {
                    var date = convert_unixtime(block.timestamp);
  • It is the asynchronous nature of javascript callbacks you are not guaranteed an order. If you need an specific order you have enforce on your side using a queue or something like that. – Ismael Jun 21 '19 at 17:54

Your Answer

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

Browse other questions tagged or ask your own question.