Calculating a sum of received bitcoins I have a list of bitcoin addresses provided by a user and I am trying to find out a sum deposited to these addresses. I am using blockexplorer.com API to obtain transactions.

This is a typical API call (for convenience only for one address) my script does. The call supports parameters from and to, these can be used to effectively streamline an entire transaction ledger.

https://blockexplorer.com/api/addrs/1Archive1n2C579dMsAu3iC6tWzuQJz8dN/txs?from=0&amp;to=20

There appears to be no error in my streamlining algorithm, but if I summarize values found in valueIn (which should presumably stand for values sent to an address), the result is completely off when compared to result returned in API call totalReceived.

https://blockexplorer.com/api/addr/1Archive1n2C579dMsAu3iC6tWzuQJz8dN/totalReceived

Why am I getting a totally different results?

Is this a correct way to find out if a certain amount was deposited to address (or addresses)?

Fun fact: blockexplorer.com returns a value of totalReceived that is different from a value returned by blockchain.info.
Transactions can have multiple outputs, and multiple inputs. The valueIn field is the sum of all of the inputs of the transaction, not the amount going toward the address you're interested in.

Instead of summing valueIn, you should make a list of all of the outputs, then filter out the ones that aren't sent to the address you're interested in, then sum those up.


  Fun fact: blockexplorer.com returns a value of totalReceived that is different from a value returned by blockchain.info.


The meaning of 'total received' is not well-defined. For example, if I take money at address A, and send it to address A, has address A "received" money? Different APIs calculate this differently.

Note: I assume you're intentionally not looking to find the balance of the address, which is well-defined.