Last active
June 14, 2016 07:41
-
-
Save bkawk/3245e56b785a71d875823fdf2b910a07 to your computer and use it in GitHub Desktop.
Get unspent transactions and total
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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