Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: echozzi on April 20, 2020, 11:28:18 AM



Title: How to determine the sender of BTC through an API
Post by: echozzi on April 20, 2020, 11:28:18 AM
Assuming I was expecting two BTC transactions of the same amount from different wallet addresses. is there an available API I can use to check which of the two addresses made the transaction?


Title: Re: How to determine the sender of BTC through an API
Post by: BrewMaster on April 20, 2020, 02:55:34 PM
Blockcypher API includes the "sender's" address in its API response.
for example from the last block:
https://api.blockcypher.com/v1/btc/main/txs/499003ee50065a93bd786f792e3f72f99c8d308940fa1e5937178650a6a80fa2?limit=50

the "1ArgjWtWL8a2yshyeJUqtTtqgqKpZFGst5" is the sender's address. you will find each address in "inputs" list under "addresses" of that input.

ps. if the payment that you receive is important you may want to start running your own full node or at least an SPV node instead of relying on centralized services such as blockchain APIs.


Title: Re: How to determine the sender of BTC through an API
Post by: echozzi on April 20, 2020, 03:07:45 PM
Thank you so much and our reply was helpful. However, assuming I wanted using a script on chron, to check for transations in my wallet from an address, can that be possible?


Title: Re: How to determine the sender of BTC through an API
Post by: TryNinja on April 20, 2020, 04:47:33 PM
Thank you so much and our reply was helpful. However, assuming I wanted using a script on chron, to check for transations in my wallet from an address, can that be possible?
You could, for example, hit Blockcypher's address API endpoint[1] to get the latest transaction and then use it to hit the endpoint posted above to get the data you need. Then do the rest of the handling on your code.

[1] https://api.blockcypher.com/v1/btc/main/addrs/1ArgjWtWL8a2yshyeJUqtTtqgqKpZFGst5


Title: Re: How to determine the sender of BTC through an API
Post by: BrewMaster on April 20, 2020, 05:04:25 PM
Thank you so much and our reply was helpful. However, assuming I wanted using a script on chron, to check for transations in my wallet from an address, can that be possible?
You could, for example, hit Blockcypher's address API endpoint[1] to get the latest transaction and then use it to hit the endpoint posted above to get the data you need. Then do the rest of the handling on your code.

[1] https://api.blockcypher.com/v1/btc/main/addrs/1ArgjWtWL8a2yshyeJUqtTtqgqKpZFGst5

the main problem is parsing the JSON response that the API sends back which would require additional libraries that are designed to do that, and i don't think it is possible to do this with a simple script.


Title: Re: How to determine the sender of BTC through an API
Post by: TryNinja on April 20, 2020, 06:08:32 PM
the main problem is parsing the JSON response that the API sends back which would require additional libraries that are designed to do that, and i don't think it is possible to do this with a simple script.
Not really. You can parse a JSON response with pretty much every existing programming language (python, js, php, etc...) without any additional library.


Title: Re: How to determine the sender of BTC through an API
Post by: odolvlobo on April 21, 2020, 07:25:42 AM
I don't know what your goal is, but it might be useful to remember that bitcoins don't have to come from an address. Also, expecting bitcoins to come from a particular address might be problematic because the sending wallet generally decides which address(es) to use.


Title: Re: How to determine the sender of BTC through an API
Post by: lucasholder on April 22, 2020, 12:23:23 PM
Thank you so much and our reply was helpful. However, assuming I wanted using a script on chron, to check for transations in my wallet from an address, can that be possible?
You could, for example, hit Blockcypher's address API endpoint[1] to get the latest transaction and then use it to hit the endpoint posted above to get the data you need. Then do the rest of the handling on your code.

[1] https://api.blockcypher.com/v1/btc/main/addrs/1ArgjWtWL8a2yshyeJUqtTtqgqKpZFGst5

the main problem is parsing the JSON response that the API sends back which would require additional libraries that are designed to do that, and i don't think it is possible to do this with a simple script.

If you're writing a shell script, you can use the jq tool for parsing the response and extracting the field(s) you want: https://stedolan.github.io/jq/tutorial/


Title: Re: How to determine the sender of BTC through an API
Post by: Initscri on April 24, 2020, 10:20:30 AM
Thank you so much and our reply was helpful. However, assuming I wanted using a script on chron, to check for transations in my wallet from an address, can that be possible?

You're probably best mentioning the programming language you plan on using for this (whether it be PHP, python etc) and then we'll go from there. Many of us can provide examples of something that could technically be run automatically every x minutes.