0

I'm currently using v2 of Blockchain.info's API and am wanting to utilise "Send Many Transaction" and am having some issues.

I have 1 wallet with many addresses, I am trying to send 2 transactions within 1 payment, their API documentation is still from v1 and is missing the '&from' from their api example, and have spent more time than I'd like to admit to get this working.

this is from there website:

http://localhost:3000/merchant/$guid/sendmany?password=$main_password&second_password=$second_password&recipients=$recipients&fee=$fee

$main_password Your Main Blockchain wallet password
$second_password Your second Blockchain Wallet password if double encryption  is enabled.
$recipients Is a JSON Object using Bitcoin Addresses as keys and the amounts to send as values (See below).
$from Send from a specific Bitcoin Address (Optional)
$fee Transaction fee value in satoshi (Must be greater than default fee) (Optional)
$note A public note to include with the transaction -- can only be attached to transactions where all outputs are greater than 0.005 BTC.(Optional)

The result I get is:

failed to open stream:HTTP request failed!

Fatal error:Maximum execution time of 120 seconds exceeded

I now the url is wrong but can anyone please help advise me what it is specifically.

So far this is what I have

// Sending addresses 
$Address1 = 'Address1';
$Address2 = 'Address2';

//Amount coming from
$From = 'Address3';

//Amounts being sent in satoshi
$Amount1 = 100000;  // 0.001 of a btc
$Amount2 = 100000;  

$recipients = urlencode(' {
    "'.$Address1.'": '.$Amount1.',  
    "'.$Address2.'": '.$Amount2.'
}');

$Guid = 'MY_GUID';      
$Password = 'MY_PASSWORD';                              

$url = 'http://localhost:3000/merchant/'.$Guid.'/sendmany?password='.$Password.'&from='.$From.'&recipients='.$recipients.''; 
// I've also tried to remove $data and put '&api_code=MY_API_CODE' after
// $recipients as this also works for other api calls for v2

$data = array('api_code' => 'MY_API_CODE');

$result = sendAmounts($url, $data);

function sendAmounts($url, $data) { 
$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',  // Also tried GET
        'content' => http_build_query($data),
    ),
);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);

return $result;
}

Thank you in advance.

  • Did you already set up your local nodejs service? – m1xolyd1an Mar 24 '16 at 12:24
  • @m1xolyd1an - yes I have set up nodejs, I can get balances, send a single payment etc.. just send many transactions is giving me grief – Dougio Mar 24 '16 at 23:16
0

As of January 2016 Blockchain.info made changes to the wallet API service that now requires you to run a local nodeJS service to handle the calls. This will require you to have root access to your webserver so you will need to use a VPS instead of a basic shared web host.

Also I don't recommend hand-coding the JSON yourself when using sendmany. Instead create an array and then use the json_encode function.

$array = array(
    "1someAddress" => 20000,
    "1someAddress2" => 150000,
    "1someAddress3" => 314159
); 
$addresses = json_encode($array);

You're not the only one that has hard time with the new version of their API. If you still need some help check out these resources.

https://www.youtube.com/watch?v=X8jsaf4sEgs
http://btcthreads.com/how-to-setup-blockchain-wallet-service/

I started a PHP library for communicating with the nodeJS service, (still needs work, some functions are missing) https://github.com/coinables/blockchain-wallet-APIv2-PHP-Library

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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