0

In this code client.createTransaction() function returns result1.txid. From that result1.txid i want to run while loop and inside that while loop I want to client.getTx() repeatably untill i get status == 1 or -1. Here i cant able to run the while loop. It shows nothing,

var coinPay = require('coinpayments');
var fs = require('fs');
var async = require("async");

var client = new coinPay({
  'key': 'XYZsdgdfgdf',
  'secret': 'XYZsdfsdfsd',
  'autoIpn': true
});

client.createTransaction({
    'currency1': 'LTCT',
    'currency2': 'LTCT',
    'amount': 1
  }, (err, result1) => {
    while (true) {
      client.getTx(result1.txn_id, (err, result) => {
        console.log(result);
        if (result.status == -1) {
          console.log("unsuccesful");
          return;
        } else if (result.status == 1) {
          console.log("succesful");
          return;
        } else
          console.log("checking");
      })
    }
  }
)
8
  • ok please share a link in comment. Commented Aug 4, 2018 at 7:18
  • instead of wasting mine and your time you could have ignored or answered my question as per code. we are learning developer not a phd guys who are being lazy. so please if u your planing to duplicate the question atleast mention your view that can be understandably with my question Commented Aug 4, 2018 at 9:01
  • Use async await Commented Aug 4, 2018 at 10:31
  • can you help me with an example? please i have tried async await Commented Aug 4, 2018 at 11:08
  • Did you read the duplicate? It explains why you can't use a while() loop like that in Javascript because you can't get any events while you're in the while loop, thus no async callbacks will ever get called. What did you not understand about the duplicate? Welcome to stack overflow, but the protocol here is that when we see a question that we've seen many answers to before, we are not supposed to repeat the same type of answer over and over - we are supposed to mark it a duplicate. That's how this place is supposed to work. If you don't understand something in the dup, you can comment. Commented Aug 4, 2018 at 21:14

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.