Author

Topic: blockchain.info api multi send HELP (Read 4106 times)

sr. member
Activity: 335
Merit: 250
April 27, 2013, 10:45:43 PM
#8
removed
hero member
Activity: 630
Merit: 502
April 27, 2013, 10:18:23 PM
#7
No problem.  Wink
sr. member
Activity: 335
Merit: 250
April 27, 2013, 10:14:48 PM
#6
ok thought so thanks
hero member
Activity: 630
Merit: 502
April 27, 2013, 10:10:35 PM
#5
The data is sent in the file_get_contents() line. (Line 31 in the example above). It's the equivalent of you opening the url stored in the variable $json_url in your Web browser. Assuming you get a 200 response and no error is returned, the funds will have been sent at this point.
sr. member
Activity: 335
Merit: 250
April 27, 2013, 09:15:53 PM
#4
how do you send the data
hero member
Activity: 630
Merit: 502
April 27, 2013, 12:36:42 PM
#3
Here's a practical example with php/MySQL.

Lets say for the sake of argument you have a MySQL database table like this:
Code:
CREATE TABLE `bitcoin_payments` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `bitcoin_address` varchar(34) NOT NULL,
  `payment_in_satoshi` bigint(20) unsigned NOT NULL DEFAULT '0',
  `transaction_hash` varchar(64) NOT NULL,
  PRIMARY KEY (`id`)
);

And in this table you have a list of payments to be made. If the payment has already been made then the transaction_hash field contains the transaction hash the payment was made with, otherwise it's empty.

Code:

$guid
="GUID_HERE";
$firstpassword="PASSWORD_HERE";
$secondpassword="PASSWORD_HERE";

// Your MySQL database login credentials here
$host="localhost"// MySQL host
$user=""// MySQL user
$pass=""// MySQL password for user above
$db=""// MySQL database to use

mysql_select_db($dbmysql_connect($host$user$pass));

$result=mysql_query("SELECT `id`, `bitcoin_address`, `payment_in_satoshi` FROM `bitcoin_payments` WHERE `transaction_hash`='' ORDER BY `id` ASC");
$recipient_list=array();
$new_paid_ids="";
if(
mysql_num_rows($result)>0)
{
    while(
$row=mysql_fetch_assoc($result))
    {
        
$new_paid_ids.=$row["id"].",";
        
$recipient_list[$row["bitcoin_address"]]=$row["payment_in_satoshi"];
    }
    
$new_paid_ids=trim($new_paid_ids",");
}
if(
count($recipient_list)>0)
{
    
$recipients=urlencode(json_encode($recipient_list));
    
$json_url "http://blockchain.info/merchant/$guid/sendmany?password=$firstpassword&second_password=$secondpassword&recipients=$recipients";
    
$json_data file_get_contents($json_url);
    if(
$http_response_header[0]=="HTTP/1.1 200 OK")
    {
        
$json_feed json_decode($json_data);
        
$error $json_feed->error;
        if(
is_null($error))
        {
            
$message $json_feed->message;
            
$txid $json_feed->tx_hash;
            
mysql_query("UPDATE `bitcoin_address` SET `transaction_hash`='".mysql_real_escape_string($txid)."' WHERE `id` IN(".$new_paid_ids.")");
            echo 
$message." - ".$txid.""
;
        }
        else
            echo 
$error;
    }
    else
        echo 
"bitchain.info returned the following http error:".$http_response_header[0];
}

?>

Please note the above is not tested but it should work in theory. Wink
sr. member
Activity: 448
Merit: 254
April 26, 2013, 05:38:51 PM
#2
I think it would be more efficient for you to answer, what errors are you experiencing?

The json module seems to be enabled by default in recent PHP versions.  The only other dependency is on the http file wrapper being enabled, in the file_get_contents call.  What is the output of var_dump(stream_get_wrappers()) ?
sr. member
Activity: 335
Merit: 250
April 25, 2013, 02:27:07 PM
#1

This code segment is from http://blockchain.info/api/blockchain_wallet_api
How do i execute this? what do i need to install, do i need to link to a json library or something. I need a step thru process here.  Thanks

Code:

$guid="GUID_HERE";
$firstpassword="PASSWORD_HERE";
$secondpassword="PASSWORD_HERE";
$amounta = "10000000";
$amountb = "400000";
$addressa = "1A8JiWcwvpY7tAopUkSnGuEYHmzGYfZPiq";
$addressb = "1ExD2je6UNxL5oSu6iPUhn9Ta7UrN8bjBy";
$recipients = urlencode('{
                  "'.$addressa.'": '.$amounta.',
                  "'.$addressb.'": '.$amountb.'
               }');

$json_url = "http://blockchain.info/merchant/$guid/sendmany?password=$firstpassword&second_password=$secondpassword&recipients=$recipients";

$json_data = file_get_contents($json_url);

$json_feed = json_decode($json_data);

$message = $json_feed->message;
$txid = $json_feed->tx_hash;

?>
Jump to: