0

I used a tutorial online to create my own block explorer (https://www.youtube.com/watch?v=laeV2slJgc8).

In this tutorial, I used "Iquidus" to create the block explorer, which uses MongoDB and Node.js. Now I want to make my own API call that will list all UTXOs for a given address.

Is there a MongoDB query I can just run to get the UTXOs or What would the code even look like to do something like that?

The call I am talking about is the same they have on "https://chainz.cryptoid.info/api.dws":

"unspent becomes available, this API is similar to blockchain.info's, it has a single active parameter in which you can pass multiple addresses separated by '|'. It returns information about unspent outputs of those addresses."

MongoDB is a schema-less database but I managed to get this:

> show collections
addresses
coinstats
markets
peers
richlists
txes
> var col_list = db.addresses.findOne(); for (var col in col_list) { print (col) ; }
_id
a_id
balance
sent
received
txs
__v
> var col_list = db.coinstats.findOne(); for (var col in col_list) {print (col) ; }
_id
coin
last_price
connections
supply
last
count
__v
> var col_list = db.markets.findOne(); for (var col in col_list) {print (col) ; }
_id
market
history
sells
buys
chartdata
__v
> var col_list = db.peers.findOne(); for (var col in col_list) {print (col) ; }
> var col_list = db.richlists.findOne(); for (var col in col_list) {print (col) ; }
_id
coin
balance
received
__v
> var col_list = db.txes.findOne(); for (var col in col_list) {print (col) ; }
_id
txid
blockhash
blockindex
timestamp
total
vout
vin
__v
> 

Desired output

{"unspent_outputs":[{"tx_hash":"819d2c6331fecf0bcda79962ed7b66c71b508a4698680b84310f4d2f67203e87","tx_ouput_n":0,"value":100000,"confirmations":63499,"script":"76a9142beec605c9a6512f55fe93ad76753e24fc8579b088ac","addr":"MBuTKxJaHMN3UsRxQqpGRPdA7sCfE1UF7n"},{"tx_hash":"819d2c6331fecf0bcda79962ed7b66c71b508a4698680b84310f4d2f67203e87","tx_ouput_n":1,"value":767048,"confirmations":63499,"script":"76a9142beec605c9a6512f55fe93ad76753e24fc8579b088ac","addr":"MBuTKxJaHMN3UsRxQqpGRPdA7sCfE1UF7n"},{"tx_hash":"7d76cc54c510f1e8f4dd4dbf4d215713245cb3fd7ec1417f852b7d34deee116f","tx_ouput_n":0,"value":1000000000,"confirmations":63439,"script":"76a9142beec605c9a6512f55fe93ad76753e24fc8579b088ac","addr":"MBuTKxJaHMN3UsRxQqpGRPdA7sCfE1UF7n"},{"tx_hash":"03033110cbe81f34c3eede0affd626a135ccea67e783f2beaf02c98ba2e721f3","tx_ouput_n":0,"value":314419,"confirmations":10977,"script":"76a9142beec605c9a6512f55fe93ad76753e24fc8579b088ac","addr":"MBuTKxJaHMN3UsRxQqpGRPdA7sCfE1UF7n"}]}
  • can you provide the database schema? – JBaczuk Aug 26 at 23:27
  • I edited my question, I hope it helps. Thank you for the reply. @JBaczuk – Oleg Aug 26 at 23:56
  • Where does the explorer get this data? Does it sync from a Bitcoin Core node? If so, why not just adjust the explorer to sync the latest UTXO set? It will be very difficult to create a query that gets unspent outputs for a given address because it will have to traverse the entire blockchain to determine which outputs are unspent. – JBaczuk Aug 27 at 0:02
  • yes, the explorer is using the core wallet to get its data and places that data into the database. Not really sure how to adjust the explorer to sync the latest UTXO set, thats why I assumed its possible to make a query of some sort, that would query the database to get that information. – Oleg Aug 27 at 0:09
  • In order to execute that query you have to search the entire blockchain for every output to any address that you own. And for each of those outputs you have to search from and including the block with that output to the latest block to see if it has been spent or not. Bitcoin core does the last part for you by maintaining a database of unspent outputs. – JBaczuk Aug 27 at 0:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.