I wanted to write a small script to parse all incoming transactions to a wallet. The wallet I'm looking at is from an OpenSource project I'm working for, to get an overview of the amounts given to the project in a certain time-range. I use the Blockchain Data API and try to parse the information from this call (includes the wallet-adress). But I can't seem to get the amount of Bitcoins that were transferred to the wallet. Sometimes there are amounts as big as 266 BTC listed, even though the real transaction was just a couple of Satoshis.

So, the question is: When I have a JSON Transaction Block like this:

   "ver":1,
   "inputs":[
      {
         "sequence":4294967295,
         "prev_out":{
            "spent":true,
            "tx_index":273950706,
            "type":0,
            "addr":"12tPhkHLjmkDfqTfvbagbnkYDU5UTu2pMp",
            "value":461323,
            "n":1,
            "script":"76a91414b04a7b66d06dd399bdb689df209ed688e9bcaa88ac"
         },
         "script":"483045022100f38ffd67d53b4c5a6f6a2543ca6217863be5b4f3a43e885a2520dbb768ba5df702203d9782af024ee9e213fb59cee1c788c70e66d66addb553b74610a1fed3df10390121026b138ff61ffeaf459c4916889d2c53894fc029c9729886714fe23ebd8a15bb32"
      }
   ],
   "block_height":480392,
   "relayed_by":"52.59.6.61",
   "out":[
      {
         "spent":false,
         "tx_index":274914673,
         "type":0,
         "addr":"1M3GipkG2YyHPDMPewqTpup83jitXvBg9N",
         "value":295902,
         "n":0,
         "script":"76a914dbd0788d294dd15704d232053790c555d1cb337888ac"
      },
      {
         "spent":false,
         "tx_index":274914673,
         "type":0,
         "addr":"18h2yt8cJSYwGSWV5nUodTgPZj9Vi5aCJS",
         "value":124987,
         "n":1,
         "script":"76a914545b2c20e7d8ded3853a2336ebedf7752cf823dd88ac"
      }
   ],
   "lock_time":0,
   "result":0,
   "size":226,
   "time":1502650024,
   "tx_index":274914673,
   "vin_sz":1,
   "hash":"02a7bf19417db6d975d48e27199cd65dcc415c5bf81ed447f945b2a4f3dc1d24",
   "vout_sz":2
},

What is the amount of Satoshis that have been added (or redeemed) from that wallet? How should I interpret the values in the json?

Transaction has inputs and outputs. "value" is Satoshi count:

  "inputs":[
  {
...
         "prev_out":{
...
            "value":461323,
...
         },
...
      }
   ],
...
   "out":[
      {
...
         "value":295902,
...
      },
      {
...
         "value":124987,
...
      }
   ],
...

To calculate fee you should calculate the difference between all inputs and outputs.

  • Unfortunately, this doenst work out. – Skalden Aug 15 '17 at 6:00
  • Take this transaction as an example (here the JSON) . Difference between in and out is 27760 Satoshi. But the real value was 2270804 Satoshi. – Skalden Aug 15 '17 at 6:06
  • To count how many Bitcoins have been gone into your wallet. You have to look at the out Objects only and especially only at those, that have your wallet-hash as adress. Those are the recieved Bitcoins. Now I just have to figure out how to count what has left the wallet. – Skalden Aug 15 '17 at 6:22
  • Now I don't understand what you want. Difference between in and out is fee. I noticed this. Your number is: inputs minus fee. What does this mean? Why this is real value? I have no idea. You noticed about "your wallet-hash". I don't know which addresses is yours, the question was about satoshi calculations from json. I gave you exhaustive answer, because these are the only satoshi values that are present inside transaction. You cannot figure out by looking only on transaction, which addresses are yours, and which are not. – Zergatul Aug 15 '17 at 8:48
  • Also your number is sum of outputs. Does this mean 2 output addresses are yours? – Zergatul Aug 15 '17 at 8:53

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.