Skip to content

Instantly share code, notes, and snippets.

@bkawk
Last active June 14, 2016 07:41
Show Gist options
  • Save bkawk/3245e56b785a71d875823fdf2b910a07 to your computer and use it in GitHub Desktop.
Save bkawk/3245e56b785a71d875823fdf2b910a07 to your computer and use it in GitHub Desktop.
Get unspent transactions and total
var bitcoin = require('bitcoinjs-lib');
var request = require('request');
function getUnspent(address) {
var url ='https://bitcoin.toshi.io/api/v0/addresses/'+address+'/unspent_outputs';
request(url, function (error, response, body) {
if (!error && response.statusCode == 200) {
var body = JSON.parse(body);
var total = 0;
var transactions = [];
for (var index = 0; index < body.length; index++) {
var total = total + body[index].amount;
transactions.push(body[index].transaction_hash);
} // END LOOP
console.log(total);
console.log(transactions);
}
})
}
(function () {
var address = '19G1r9AvnsN128jcHPsJUrMW1LLXAoFPRi';
getUnspent(address);
})();
{
"name": "unspent-total",
"version": "1.0.0",
"description": "Get all the unspent transactions for an address and the total unspent Satoshi",
"main": "index.js",
"scripts": {
"start": "nodemon index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "@bkawk",
"license": "MIT",
"dependencies": {
"bitcoinjs-lib": "^2.2.0",
"request": "^2.72.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment