Skip to content

Instantly share code, notes, and snippets.

@ryandotsmith
Last active Aug 29, 2015
Embed
What would you like to do?
Demonstrate transaction confidence using Chain.com's Bitcoin API
var chain = require('chain-node');
var confidant = function(txid, retries, cb) {
chain.getTransaction(txid, function(err, resp) {
if(resp.propagation_level > 0.9) {
cb(resp.propagation_level);
} else {
if(retries > 60) {
cb(null);
} else {
setTimeout(function() {
confidant(txid, retries + 1, cb);
}, 500);
}
}
});
}
chain.sendTransaction('0100000001ec...'), function(err, resp) {
var startTime = new Date();
confidant(resp.hash, 0, function(level) {
if(level) {
var ttc = startTime - new Date();
console.log("Chain reports propagation level: " + level);
console.log("Time to confidence level: " + ttc);
} else {
console.log("Chain was unable to report high propagation level.");
}
});
});
@mishak87
Copy link

mishak87 commented Aug 27, 2014

19 sould be chain.sendTransaction('0100000001ec...', function(err, resp) { it has one extra )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment