0

I would like to watch a set of Bitcoin addresses and be able to execute some logic as they receive a payment.

According to this answer it can be done using blockchain.info:

const Socket = require('blockchain.info/Socket');
const mySocket = new Socket();
mySocket.onTransaction(function() {
  console.log(arguments);
});

The code works just fine and I'm getting notified about transactions, I can even filter and watch specific addresses (using an options parameter) but I'm not clear at all about the meaning of the fields. There are multiple fields in a transaction (here is an example one below). Which fields should I inspect in order to know the target address, the amount that came in and if it is confirmed?

enter image description here

1 Answer 1

2

Which fields should I inspect in order to know the target address, the amount that came in and if it is confirmed?

The answer seems obvious, so I may be missing some aspect of your question

the target address

That would be both JSON.0.out.0.addr and JSON.0.out.1.addr plus any other JSON.0.out.*.addr

Remember that not all Bitcoin scripts can be represented as an address.

the amount ...

The corresponding value fields show the amount of Satoshi being sent to each address.

...that came in

The input amount of the transaction is provided by the sum of the JSON.0.inputs.*.prev_out.value

and if it is confirmed?

You need to refer to other data to count confirmations. At a minimum you'd need to know the current block height and the block height of the first block containing this transaction.

I'm not familiar with this API so can't make any suggestion. Maybe the API includes a function to which you can pass the transaction ID (JSON.0.hash) to get information about the block containing that transaction. Maybe there is an onBlock() method you can use to process block data?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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