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");
})
}
}
)
while()loop like that in Javascript because you can't get any events while you're in thewhileloop, 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.