Search code examples
blockchainblockchain.info-api

I want to parse blockchain.info API info


First, thanks for anyone that can help me with this.

I work in bitcoin research, and I use blockchain.com API to retrieve some of the information about bitcoin transactions. as an example, if I extract the transactions for the address 1ADSb1ZZ9k3NsDf3JTQCQ4mb8bthiAN6NJ, I get four records, and one of them is the transaction https://www.blockchain.com/btc/tx/69b98a4476767e6fc40f8c33b3aec7fe83b7a7d3f8c7e92203b00c6be5afbdb3

My question, how do I know exactly from the returned fields the address 1ADSb1ZZ9k3NsDf3JTQCQ4mb8bthiAN6NJ paid to which address in the output side? and what is the meaning for the fields in the returned results like n, tx_index, etc. the raw data can be accessed through the website https://blockchain.info/rawaddr/1ADSb1ZZ9k3NsDf3JTQCQ4mb8bthiAN6NJ

So in short terms, I want to understand more about the fields meaning and how to track the payments of a specific address to which address as in the example on the transactions attached, how can I recognize each address sent money to any address..

{'block_height': 598496,
      'block_index': 0,
      'hash': '69b98a4476767e6fc40f8c33b3aec7fe83b7a7d3f8c7e92203b00c6be5afbdb3',
      'inputs': [{'prev_out': {'addr': '1ELHDQXk9oFN3oNekrjsuEgdgs9PREhbP8',
                               'n': 0,
                               'script': '76a914923f12b92a44b2bebdee1629dc56b10b1551875b88ac',
                               'spending_outpoints': [{'n': 0,
                                                       'tx_index': 0}],
                               'spent': True,
                               'tx_index': 0,
                               'type': 0,
                               'value': 342000},
                  'script': '483045022100ca541d97ac125eab86d1bb7d8cbd57badbaeb03b4a5ca8c3ffb09e6f4287250a02204cc8974b28d2d9d011fab69aa71931078e3fd7b161e8fa00f0529c0202d0c958012102fa53aa0f511a3f17ee404af88c25437efafe22043e2648ca9c84540d0cbfbfc3',
                  'sequence': 4294967295,
                  'witness': ''},
                 {'prev_out': {'addr': '1LcxEYYTmZzpFBT1NRjMHJaPxQdoqjRUNz',
                               'n': 1,
                               'script': '76a914d7370e1fa4287252343681b303ffa0ae49aae67488ac',
                               'spending_outpoints': [{'n': 0,
                                                       'tx_index': 0}],
                               'spent': True,
                               'tx_index': 0,
                               'type': 0,
                               'value': 342000},
                  'script': '4730440220039c37fd0c0bb6ed6ee8e4d85fdb9b48d26b4d94d9df837e401ab98aaca0495a0220181248ddd1a42e57cea6a5b5f81fa52459c342c24494f72e633d7aa8fe32fd850121028402d935c4360218ff7a1471b0b465e5aacda16e44a9768e19062fd7c5e08701',
                  'sequence': 4294967295,
                  'witness': ''},
                 {'prev_out': {'addr': '1ADSb1ZZ9k3NsDf3JTQCQ4mb8bthiAN6NJ',
                               'n': 1,
                               'script': '76a91465137b65f80173c7fd3dcb898f40fd3fed243c7988ac',
                               'spending_outpoints': [{'n': 0,
                                                       'tx_index': 0}],
                               'spent': True,
                               'tx_index': 0,
                               'type': 0,
                               'value': 342000},
                  'script': '47304402201f984f7dccb2e536e22e896b3220c84b84cece5327c73a85da8bc6b8dca41bcc022045aa417d039f611779f5603f944e28e7a26094e8a8db44d5c1eb21f36e65ebb9012102b039f2a05824c9172f35a4548732e03724d88283241becc72d0dc2fbef18787c',
                  'sequence': 4294967295,
                  'witness': ''},
                 {'prev_out': {'addr': '1AMk76C3A8pLCfzm9YzaR3x2bdt9RZpNMw',
                               'n': 0,
                               'script': '76a91466a56efb73d51f5da3ba4e417f1da6f72d75053488ac',
                               'spending_outpoints': [{'n': 0,
                                                       'tx_index': 0}],
                               'spent': True,
                               'tx_index': 0,
                               'type': 0,
                               'value': 342000},
                  'script': '483045022100d936b8baf3b2a85e570a96d73192690b7714604277041a9846454c1a8510688202207aa240aa837ec2fa86e499d36cac42c63c23522a66a3698727ee9abfef0f1b680121020450fbd3d3191b5c632f263676e8a0a4cf286ade84efb3df156426b426660754',
                  'sequence': 4294967295,
                  'witness': ''}],
      'lock_time': 0,
      'out': [{'addr': '1BTa8D9QY38abvApj5yiahh4nJ3XaTfbWA',
               'n': 0,
               'script': '76a91472b7b93efd311bbce2234913972fe5459d69807d88ac',
               'spending_outpoints': [{'n': 9, 'tx_index': 0}],
               'spent': True,
               'tx_index': 0,
               'type': 0,
               'value': 133591},
              {'addr': '3Nd9T4GqjefS9gzM7SCENGh9tUvUU4Mp8t',
               'n': 1,
               'script': 'a914e59f42949527e3411b9fbe1cbfba1ec1606d08ff87',
               'spending_outpoints': [{'n': 12, 'tx_index': 0}],
               'spent': True,
               'tx_index': 0,
               'type': 0,
               'value': 1223069}],
      'relayed_by': '0.0.0.0',
      'result': -342000,
      'size': 666,
      'time': 1570559470,
      'tx_index': 0,
      'ver': 1,
      'vin_sz': 4,
      'vout_sz': 2,
      'weight': 2664}

I appreciate your help. I am struggling in this for quit a time now


Solution

  • Bitcoin transactions have an input/ouput model, I suggest you study up on that: https://en.bitcoin.it/wiki/Transaction, it will answer all of your questions.

    I'll explain. Your question to which address did 1ADSb1ZZ9k3NsDf3JTQCQ4mb8bthiAN6NJ pay doesn't make sense because it, along with 3 other addresses paid out to 2 different addresses. In this case, it is usually one address received 1 amount and the second address received change (back to the original owner). To understand what I mean, I'll explain how a transaction is created on Bitcoin.

    Scenario

    User A wants to send .1 BTC to user B. In order to do that, they must gather up enough previous transaction outputs (where they received Bitcoin) and use them as inputs to the new transaction. So, let's say last week user C sent .05 BTC to user A, and user D sent .1 BTC to user A. You might think user A can just grab the output from user D's transaction and send that to B, but you must include a small fee for the miner in order to get your transaction added to the a block in the blockchain (miners will almost never mine a transaction for free, they get paid the transaction fee, as well as the block reward when they mine a block).

    So, in order to cover the fee, let's say it's 0.00003 BTC. User A needs to use both previous outputs so there will be a total of 0.15 BTC sent. Now, you have to spend all of the input, so user A would obviously not want to send that much if they only owe 0.1 BTC so user A will create a transaction which sends 0.1BTC to user A, and 0.04997 BTC (0.05 minus the transaction fee) back to themselves. This is called the change address, and usually is not the same as any address user A has previously used. This is for privacy reasons, so it is harder to tell who received the Bitcoin, and who got the change back if someone was trying to track users spending.