Bitcoin Forum
June 14, 2024, 05:38:58 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to get all addresses and associated txs for an XPUB with Blockchain.com API?  (Read 105 times)
ykt (OP)
Newbie
*
Offline Offline

Activity: 4
Merit: 1


View Profile
October 16, 2022, 01:45:35 PM
 #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":"<sample xpub>",
         "change_index":10,
         "account_index":18,
         "final_balance":0,
         "n_tx":32,
         "total_received": <obfuscated>,
         "total_sent":<obfuscated>
      }
   ],
   "wallet":{
      "final_balance":0,
      "n_tx":32,
      "n_tx_filtered":32,
      "total_received":<obfuscated>,
      "total_sent":<obfuscated>
   },
   "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.
jackg
Copper Member
Legendary
*
Offline Offline

Activity: 2856
Merit: 3071


https://bit.ly/387FXHi lightning theory


View Profile
October 16, 2022, 02:01:06 PM
 #2

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).
nc50lc
Legendary
*
Online Online

Activity: 2450
Merit: 5701


Self-proclaimed Genius


View Profile
October 17, 2022, 04:05:20 AM
 #3

-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.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!