Author

Topic: List transactions for given address with API call (Read 251 times)

copper member
Activity: 630
Merit: 2614
If you don’t do PGP, you don’t do crypto!
The difference is that Blockstream’s Esplora is open-source, and you can install it locally.  This is important, if you don’t want to give some database out there a neat little list of every address that interests you—plus timestamps of your queries.  The timing and order of your queries are metadata which can be used to draw further inferences.

Here's the thing about Esplora. If someone's going to make a self-hosted explorer, it will require a DB or some kind of persistent storage to be set up alongside it so that things like get-all-transactions-from-address which aren't natively supposed by full nodes can be done.

Of course!

Does Esplora connect to some local DB (or even use some key-value store)?

Of course!

Maybe it does, because the command to launch it makes you connect some Docker volume to it. But as far as I can see in the README, I don't see any way to pass the IP address of a full node. So where does it get its queries from?

The README links to the following, which in turn links back to the documentation for setting up the Esplora stack with Docker.  N.b. that if you are only running automated processes, this is really the piece that you want:

Esplora - Electrs backend API

A block chain index engine and HTTP API written in Rust based on romanz/electrs.

Used as the backend for the Esplora block explorer powering blockstream.info.

API documentation is available here.

Documentation for the database schema and indexing process is available here.

Installing & indexing

Install Rust, Bitcoin Core (no txindex needed) and the clang and cmake packages, then:

Code:
$ git clone https://github.com/blockstream/electrs && cd electrs
$ git checkout new-index
$ cargo run --release --bin electrs -- -vvvv --daemon-dir ~/.bitcoin

# Or for liquid:
$ cargo run --features liquid --release --bin electrs -- -vvvv --network liquid --daemon-dir ~/.liquid

See electrs's original documentation for more detailed instructions. Note that our indexes are incompatible with electrs's and has to be created separately.

The indexes require 610GB of storage after running compaction (as of June 2020), but you'll need to have free space of about double that available during the index compaction process. Creating the indexes should take a few hours on a beefy machine with SSD.

To deploy with Docker, follow the instructions here.

Light mode

For personal or low-volume use, you may set --lightmode to reduce disk storage requirements by roughly 50% at the cost of slower and more expensive lookups.

[...more useful information...]
jr. member
Activity: 102
Merit: 5
GameBit - The Network
So, thus far, this thread has seen recommendations for three different explorer APIs.

The difference is that Blockstream’s Esplora is open-source, and you can install it locally.  This is important, if you don’t want to give some database out there a neat little list of every address that interests you—plus timestamps of your queries.  The timing and order of your queries are metadata which can be used to draw further inferences.

As a matter of policy, I assume that every block explorer is a surveillance operation.  Don’t trust any of them!  What I like about Blockstream is that they make it so that you don’t need to trust them:  Run what is essentially your own copy of Blockstream.info on your own machine!  (And if you do query their server, then you should at least use their v3 onion so that you leak less information to them.  And you should learn how to do Tor circuit isolation.)



Am I the only one who stops to think about what information I am giving out when I query other people’s databases?  Or in the Age of Facebook, is that type of concern just passé?

You can easily choose your own explorer then. With a node, you setted up for yourself. Or even if you want to your own explorer, code it for yourself, then you have a slightly better overview about the things going on in your projekt. It much more free to deligate your own function as API Provider.
legendary
Activity: 2758
Merit: 6830
Does Esplora connect to some local DB (or even use some key-value store)? Maybe it does, because the command to launch it makes you connect some Docker volume to it. But as far as I can see in the README, I don't see any way to pass the IP address of a full node. So where does it get its queries from?
You can use it with a public API like Blockstreams' (basically only hosting your own front end) or self-host your own Esplora API server with a local node, either by letting the script setup one for you or mounting the docker volume to your existent node path: https://github.com/Blockstream/esplora#how-to-run-the-explorer-for-bitcoin-mainnet

The former is still privacy-bad, since you're hiting a third-party API just like you were using Blockstreams' explorer.
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
The difference is that Blockstream’s Esplora is open-source, and you can install it locally.  This is important, if you don’t want to give some database out there a neat little list of every address that interests you—plus timestamps of your queries.  The timing and order of your queries are metadata which can be used to draw further inferences.

Here's the thing about Esplora. If someone's going to make a self-hosted explorer, it will require a DB or some kind of persistent storage to be set up alongside it so that things like get-all-transactions-from-address which aren't natively supposed by full nodes can be done.

Does Esplora connect to some local DB (or even use some key-value store)? Maybe it does, because the command to launch it makes you connect some Docker volume to it. But as far as I can see in the README, I don't see any way to pass the IP address of a full node. So where does it get its queries from?
copper member
Activity: 630
Merit: 2614
If you don’t do PGP, you don’t do crypto!
So, thus far, this thread has seen recommendations for three different explorer APIs.

The difference is that Blockstream’s Esplora is open-source, and you can install it locally.  This is important, if you don’t want to give some database out there a neat little list of every address that interests you—plus timestamps of your queries.  The timing and order of your queries are metadata which can be used to draw further inferences.

As a matter of policy, I assume that every block explorer is a surveillance operation.  Don’t trust any of them!  What I like about Blockstream is that they make it so that you don’t need to trust them:  Run what is essentially your own copy of Blockstream.info on your own machine!  (And if you do query their server, then you should at least use their v3 onion so that you leak less information to them.  And you should learn how to do Tor circuit isolation.)



Am I the only one who stops to think about what information I am giving out when I query other people’s databases?  Or in the Age of Facebook, is that type of concern just passé?
legendary
Activity: 2352
Merit: 6089
bitcoindata.science
Is there a API call which returns all transactions for a given bitcoin address?

You can use a third party API for that.

for example, just type any address here and get all transactions from that address.

https://chain.so/api/v2/address/btc/1GzxTK4uAWhm7ukw3f65xK37S2bxZLKDWY
response:
Code:
{
  "status" : "success",
  "data" : {
    "network" : "BTC",
    "address" : "1GzxTK4uAWhm7ukw3f65xK37S2bxZLKDWY",
    "balance" : "0.00000000",
    "received_value" : "0.09957731",
    "pending_value" : "0.00000000",
    "total_txs" : 1,
    "txs" : [
      {
        "txid" : "9be4a26b5a3504969791412fb3857a1aed893e5c62524e4bed12d4ac1afc5121",
        "block_no" : 679364,
        "confirmations" : 1055,
        "time" : 1618501196,
        "outgoing" : {
          "value" : "0.09957731",
          "outputs" : [
            {
              "output_no" : 0,
              "address" : "1AJMoDqeBQFufLtJvm8Zvft9ymtg2x4UcP",
              "value" : "0.00650000",
              "spent" : {
                "txid" : "6a45805d629bfbc1ad46c3150cbdae7a01a6bd47291fa290e7a2d4b6d1573789",
                "input_no" : 2
              }
            },
            {
              "output_no" : 1,
              "address" : "13vBVz3xhJd1dwrM5HvguKRr5kKzbu21ZM",
              "value" : "0.09285456",
              "spent" : {
                "txid" : "38ddbca2a26567a08a4f87cecf31f27bbb11015177fd753a29a851dd28b5a1db",
                "input_no" : 0
              }
            }
          ]
        }
      },
      {
        "txid" : "ce47e3a23679be2e0ffd674cf2d7194d3d7b4bac309d214a200f3b4739103d7e",
        "block_no" : 679358,
        "confirmations" : 1061,
        "time" : 1618500015,
        "incoming" : {
          "output_no" : 1,
          "value" : "0.09957731",
          "spent" : {
            "txid" : "9be4a26b5a3504969791412fb3857a1aed893e5c62524e4bed12d4ac1afc5121",
            "input_no" : 0
          },
          "inputs" : [
            {
              "input_no" : 0,
              "address" : "1Nq8PhFYuvAw34Hwfrpx6Ngq2JiXBhBX5i",
              "received_from" : {
                "txid" : "e47ce82ba9cece270c4c5ef0b5dfb90e73b26ae9ad9cc3316c9eb5ff2d098c5f",
                "output_no" : 1
              }
            }
          ],
          "req_sigs" : 1,
          "script_asm" : "OP_DUP OP_HASH160 af7fe30f43fdbd7e4bfe4e88bc658f610f14d460 OP_EQUALVERIFY OP_CHECKSIG",
          "script_hex" : "76a914af7fe30f43fdbd7e4bfe4e88bc658f610f14d46088ac"
        }
      }
    ]
  },
  "code" : 200,
  "message" : ""
}
copper member
Activity: 630
Merit: 2614
If you don’t do PGP, you don’t do crypto!
getrawtransaction returns the transaction data of a given transaction id.

Is there a API call which returns all transactions for a given bitcoin address?

If not, which framework do you recommend to build such a query / database?

I presume that you want to be able to query any arbitrary address, even one not in any local wallet.  A node does not itself maintain the necessary indices, which are relatively large and resource-intensive.  Try installing this locally, and then calling its API:

https://github.com/Blockstream/esplora

The Esplora API can also be used on blockstream.info.  For example, I see (JSON) (onion) that this puzzle is not solved!
jr. member
Activity: 102
Merit: 5
GameBit - The Network
Look at how the mempool block explores gets the api data.

https://github.com/janoside/btc-rpc-explorer/blob/789f6436f75a78bbf7c833df56b1271bcc32de37/app/api/blockchainAddressApi.js#L7

Code:
function getAddressDetails(address, scriptPubkey, sort, limit, offset) {
return new Promise(function(resolve, reject) {
if (address.startsWith("bc1")) {
reject({userText:"blockchain.com API does not support bc1 (native Segwit) addresses"});

return;
}

if (sort == "asc") {
// need to query the total number of tx first, then build paging info from that value
var options = {
url: `https://blockchain.info/rawaddr/${address}?limit=1`,
headers: {
'User-Agent': 'request'
}
};

request(options, function(error, response, body) {
if (error == null && response && response.statusCode && response.statusCode == 200) {
var blockchainJson = JSON.parse(body);

var txCount = blockchainJson.n_tx;
var pageCount = parseInt(txCount / limit);
var lastPageSize = limit;
if (pageCount * limit < txCount) {
lastPageSize = txCount - pageCount * limit;
}

var dynamicOffset = txCount - limit - offset;
if (dynamicOffset < 0) {
limit += dynamicOffset;
dynamicOffset += limit;
}

getAddressDetailsSortDesc(address, limit, dynamicOffset).then(function(result) {
result.txids.reverse();

resolve({addressDetails:result});

}).catch(function(err) {
utils.logError("2308hsghse", err);

reject(err);
});

} else {
var fullError = {error:error, response:response, body:body};

utils.logError("we0f8hasd0fhas", fullError);

reject(fullError);
}
});
} else {
getAddressDetailsSortDesc(address, limit, offset).then(function(result) {
resolve({addressDetails:result});

}).catch(function(err) {
utils.logError("3208hwssse", err);

reject(err);
});
}
});
}
legendary
Activity: 2618
Merit: 6452
Self-proclaimed Genius
Is there a API call which returns all transactions for a given bitcoin address?
There's only listtransactions in bitcoin core but it's a wallet RPC.

If it's for a simple query, not a for a project, you can import it to a 'disabled private key' - 'blank wallet' as a watch-only address. (createwallet | importaddress),
after rescan, you can use the command to list the transactions of that address, through:
Code:
bitcoin-cli -rpcwallet="wallet_name" listtransactions "*" "999"
(https://bitcoincore.org/en/doc/0.21.0/rpc/wallet/listtransactions/)
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
You'd use both Blockchain.com's API and getrawtransaction together. You put your address in the URL naufragus posted (which is https://blockchain.info/rawaddr/[ADDR_HERE] for clarity), query it from a script, or just use "curl" if you want to do it by hand from the command line.

After that, according to this stack exchange answer, the txs key of the JSON holds an array of transactions for that address, which you can query on a node using getrawtransaction. It must have -txindex on to work.

jq's output for the transaction list will be rather long for addresses with hundreds of transactions to them, so you'd use a JSON library in your scripting language to convert it into an array, and fetch individual transactions using indices.
newbie
Activity: 29
Merit: 50
You can try blockchain.com:

Code:
% curl -L --compressed "https://blockchain.info/rawaddr/[ADDR_HERE]" | jq

I have got a shell script called binfo.sh which does some API calls and format the data, don't know if you want to build your own db tho.
https://github.com/mountaineerbr/markets/blob/master/binfo.sh
newbie
Activity: 16
Merit: 4
getrawtransaction returns the transaction data of a given transaction id.

Is there a API call which returns all transactions for a given bitcoin address?

If not, which framework do you recommend to build such a query / database?

Jump to: