Bitcoin Forum
May 13, 2024, 02:54:41 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Warning: One or more bitcointalk.org users have reported that they strongly believe that the creator of this topic is a scammer. (Login to see the detailed trust ratings.) While the bitcointalk.org administration does not verify such claims, you should proceed with extreme caution.
Pages: [1]
  Print  
Author Topic: [Solved] Blockchain API Callback  (Read 847 times)
WingTsun (OP)
Member
**
Offline Offline

Activity: 120
Merit: 10

❖ Bitcoin Enthusiast / Developer ❖


View Profile
August 27, 2015, 12:04:15 AM
Last edit: August 29, 2015, 08:01:41 PM by WingTsun
 #1

I just stumbled across a problem, creating a PHP "CALLBACK". Everything is working fine, except I can not find how can I grab the SENDERS Wallet. All other parameters are provided.

I have red the BlockChain API, and it shows only how to grab receivers wallet (Your Own, which received the transaction). Here are the parameters they provide:

  value - The value of the payment received in satoshi (not including fees). Divide by 100000000 to get the value in BTC.
  transaction_hash - The transaction hash.
  input_address - The bitcoin address that received the transaction.
  confirmations - The number of confirmations of this transaction.
  {Custom Parameters} - Any parameters included in the callback URL will be past back to the callback URL in the notification.

That does not make any sense for me, why there is no example how to grab the senders wallet, since my script needs to save the senders wallet for further use.

Any help would be appreciated.
Thank you, WingTsun.


❖ Professional Bitcoin Developer ❖ Ignore the negative feedback ❖
1715568881
Hero Member
*
Offline Offline

Posts: 1715568881

View Profile Personal Message (Offline)

Ignore
1715568881
Reply with quote  #2

1715568881
Report to moderator
In order to achieve higher forum ranks, you need both activity points and merit points.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715568881
Hero Member
*
Offline Offline

Posts: 1715568881

View Profile Personal Message (Offline)

Ignore
1715568881
Reply with quote  #2

1715568881
Report to moderator
1715568881
Hero Member
*
Offline Offline

Posts: 1715568881

View Profile Personal Message (Offline)

Ignore
1715568881
Reply with quote  #2

1715568881
Report to moderator
achow101
Staff
Legendary
*
Offline Offline

Activity: 3388
Merit: 6635


Just writing some code


View Profile WWW
August 27, 2015, 12:11:49 AM
 #2

Since the sender could be sending from multiple addresses or through a shared sending transaction, it is possible that blockchain omitted this feature because there is no guarantee (except for 1 input 1 output transactions) which input is going to you.

A rather roundabout way would be to take the transaction hash they provide and query for all of the inputs in that transaction and pull the sending addresses from there.

DannyHamilton
Legendary
*
Offline Offline

Activity: 3388
Merit: 4653



View Profile
August 27, 2015, 12:20:11 AM
 #3

There is no such thing as a "sending address" at the technical level of bitcoin.

The sender might not even be using a wallet to send the transaction.

If you want to know what address to use to send bitcoins to someone, ASK THEM.  Any other method is at best a guess, and at worst completely wrong.

coinableS
Legendary
*
Offline Offline

Activity: 1442
Merit: 1179



View Profile WWW
August 27, 2015, 01:25:01 AM
 #4

Danny and Knight are right, there is no sure way to do this, since there can be multiple input addresses that sent you the funds.
However there is a way to get the 1st input sending address of the most recent transaction to a particular address.

I did a video tutorial on how to do this a few months back with blockchain.info.

https://youtu.be/_K270ufQ6ho?t=1m

Go here -> https://blockchain.info/api/blockchain_api
Scroll down to the single address area:
Then you'll take your $input_address and plug it in: https://blockchain.info/address/$bitcoin_address?format=json
Replace $bitcoin_address with the input_address that received the funds.
and then you can pull out the most recent transaction and then pull out the address from the inputs array.
Again watch the video ^^

Your code will look something like:

Code:
<?php
$input_address 
"1someBitcoinAddress";
$url "https://blockchain.info/address/$input_address?format=json";
$jsonData json_decode(file_get_contents($url), true);
$sendingAddress $jsonData["txs"][0]["inputs"][0]["prev_out"]["addr"];
echo 
"This address ".$sendingAddress." sent the most recent transaction";
//or you can enter the $sendingAddress to a DB
?>


If you want to get all the input addresses that sent for the most recent transaction you will just create a loop that counts the number of inputs
something like:
Code:
        $n_inputs = count($jsonData["txs"][0]["inputs"]);	
for($ii = 0; $ii < $n_inputs; $ii++){
$inValue = $jsonData["txs"][0]["inputs"][$ii]["prev_out"]["addr"];
        }

I also did a video on making the loops but with chain.com API
https://youtu.be/OUdGJK-sJ2k?t=2m33s  start video at 2:33

WingTsun (OP)
Member
**
Offline Offline

Activity: 120
Merit: 10

❖ Bitcoin Enthusiast / Developer ❖


View Profile
August 27, 2015, 02:12:05 AM
 #5

Thank you guys for the replies, now it's clear to me.  Wink

❖ Professional Bitcoin Developer ❖ Ignore the negative feedback ❖
WingTsun (OP)
Member
**
Offline Offline

Activity: 120
Merit: 10

❖ Bitcoin Enthusiast / Developer ❖


View Profile
August 29, 2015, 07:17:12 PM
 #6

So, the only way I could come up with, in order to keep system max easy for users is:

- They click a "Start" button;
- Window pops-up asking for the users BTC Wallet;
- After user enters his Wallet, system generates a new one, and provides it for the user in the same Window;
- Further, system enters the details in the DataBase, and the Callback waits for this specific transaction in the newly generated wallet by the system.

Will this approach work? I mean, By this method I should be able to see in the Callback from which Wallet is the coins sent, right?

Thank you, WingTsun.

❖ Professional Bitcoin Developer ❖ Ignore the negative feedback ❖
coinableS
Legendary
*
Offline Offline

Activity: 1442
Merit: 1179



View Profile WWW
August 29, 2015, 07:28:37 PM
 #7

So, the only way I could come up with, in order to keep system max easy for users is:

- They click a "Start" button;
- Window pops-up asking for the users BTC Wallet;
- After user enters his Wallet, system generates a new one, and provides it for the user in the same Window;
- Further, system enters the details in the DataBase, and the Callback waits for this specific transaction in the newly generated wallet by the system.

Will this approach work? I mean, By this method I should be able to see in the Callback from which Wallet is the coins sent, right?

Thank you, WingTsun.

Yes that would work and that's how a lot of sites that accept bitcoin as payments online track orders. Generate a new deposit address for each user then you are easily able to tell who sent in the funds. The above would work by asking them for their receiving address and then assigning it to a unique deposit address. That way you will know what address to send the funds back to. 

WingTsun (OP)
Member
**
Offline Offline

Activity: 120
Merit: 10

❖ Bitcoin Enthusiast / Developer ❖


View Profile
August 29, 2015, 07:33:28 PM
 #8

Ok, thank you. I am now checking the Documentation, now I just need to confirm the correct way of obtaining the senders wallet (In this case it is the newly generated wallet) in the CallBack.

The CallBack response looks like this:

Code:
{
    "fee_percent":0,
    "destination":"1A8JiWcwvpY7tAopUkSnGuEYHmzGYfZPiq",
    "input_address":"1KZoUuPWFAeyVySHAGqvTUDoX6P3ntuLNF",
    "callback_url":"http://yoururl.com"
}

So, I should be able to get he senders wallet (the generated one) like this right?

Code:
$input_address = $_GET['input_address'];

❖ Professional Bitcoin Developer ❖ Ignore the negative feedback ❖
coinableS
Legendary
*
Offline Offline

Activity: 1442
Merit: 1179



View Profile WWW
August 29, 2015, 07:53:18 PM
 #9

Correct, the input_address parameter is automatically provided with blockchain.info's callback as a GET.

So you can use that input address to run a database query and see who that address belongs to.
Something like   SELECT * FROM mytable WHERE depositaddress = '$input_address'

WingTsun (OP)
Member
**
Offline Offline

Activity: 120
Merit: 10

❖ Bitcoin Enthusiast / Developer ❖


View Profile
August 29, 2015, 07:56:16 PM
 #10

Thank you, now that you confirmed that this parameter will be the generated wallet, I have everything i need to implement this solution. Huge thanks to you. I am marking this as "[Solved]".

❖ Professional Bitcoin Developer ❖ Ignore the negative feedback ❖
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!