Author

Topic: How to get all addresses and associated txs for an XPUB with Blockchain.com API? (Read 137 times)

legendary
Activity: 2646
Merit: 6681
Self-proclaimed Genius
-snip- Every item under the `txs` list has inputs and outputs, and that's about the point where I'm stuck right now.

How do I figure out whether this is a "spend" or "receive" transaction in relation to a given xpub and what is the associated address?

Let's use this result as an example:
Code:
  "txs":[
      {
         "hash":"0202b8ba785d8befdbbeca1641a981d371ddfc2f5216a2d1fd78de7e8e460478",
         "ver":2,
         "vin_sz":2,
         "vout_sz":1,
         "size":335,
         "weight":1340,
         "fee":820,
         "relayed_by":"0.0.0.0",
         "lock_time":640369,
         "tx_index":4222712286272463,
         "double_spend":false,
         "time":1595650444,
         "block_index":640678,
         "block_height":640678,
         "inputs":[
.
.
.
         ],
         "out":[
.
.
.
         ],
         "result":-1820,
         "balance":546
      },
Below each transaction, there should be a "result" and "balance",
If the result is a negative value, that means that it's a "spend" transaction, "receive" if positive.
The associated address(es) are the "addr" in the "inputs" if it's a spend txn, in the "out" if it's a receive txn.
copper member
Activity: 2856
Merit: 3071
https://bit.ly/387FXHi lightning theory
Why didn't you give us an example of what's in the txs?

When testing this with an xpub the two main things I can see that are probably useful are "balance" and "result" that come with each transaction (or seem to).
ykt
newbie
Activity: 4
Merit: 1
Hi,

I'm trying to get all addresses and their transactions for an xpub using Blockchain.com API, and right now pretty much drown drowning under the amount of new information Smiley
So hope somebody can clarify this for me.

As a first step, I'm sending a `multiaddr` request like this
Code:
GET https://blockchain.info/multiaddr?active=xpub...

And in return, I'm getting a JSON struct with three keys - `addresses`, `wallet` and `txs`

Code:

{
   "addresses":[
      {
         "address":"",
         "change_index":10,
         "account_index":18,
         "final_balance":0,
         "n_tx":32,
         "total_received": ,
         "total_sent":
      }
   ],
   "wallet":{
      "final_balance":0,
      "n_tx":32,
      "n_tx_filtered":32,
      "total_received":,
      "total_sent":
   },
   "txs":[...]
}

Every item under the `txs` list has inputs and outputs, and that's about the point where I'm stuck right now.

How do I figure out whether this is a "spend" or "receive" transaction in relation to a given xpub and what is the associated address?

Thank you.
Jump to: