Reputation: 33
I'm trying to send a payment via the blockchain API v2. I'm using PHP and Curl.
blockchain-wallet-service : 0.26.0 v
node.js : 8.9.0 v
I can generate bitcoin addresses, get my balance and interact with my wallet, but for an unknown reason, I cannot SEND payments via the API, please help I have looked up many websites for answers.
My PHP code (just testing) to send a payment:
$my_api_key = 'xxxxx';
$guid='xxxxx';
$firstpassword='xxxx';
$second_password = "xxxx";
$amount = '30000';
$to = '1AQDhKrjvAonjLAUv4PzM9NjGzZZ4HEpU1';
$fee = '2000';
$root_url = 'http://localhost:3000/merchant/'.$guid.'/payment';
$parameters = 'to='.$to.'&amount='.$amount.'&password='.$firstpassword.'&fee='.$fee.'&second_password='.$second_password;
$response = Curl::to($root_url . '?' . $parameters)->get();
return $response;
On the console I get the following error:
error: [object object] the response gives me : {"error":"Unexpected error, please try again"}
I tested both my passwords, my API code + my wallet ID, all 100% correct.
Upvotes: 2
Views: 1864
Reputation: 41
Try this:
$address = null;
try {
// Uncomment to send
// var_dump($Blockchain->Wallet->send($address, "0.001"));
} catch (\Blockchain\Exception\ApiError $e) {
echo $e->getMessage() . '<br />';
}
// Multi-recipient format
$recipients = array();
$recipients[$address] = "0.001";
try {
// Uncomment to send
// var_dump($Blockchain->Wallet->sendMany($recipients));
} catch (Blockchain_ApiError $e) {
echo $e->getMessage() . '<br />';
}
Upvotes: 0
Reputation: 1
The "&from" parameter must be included. It is not optional as the documentation said. however you can set the parameter to 0
...................
$root_url = 'http://localhost:3000/merchant/'.$guid.'/payment'; $parameters = 'to='.$to.'&amount='.$amount.'&password='.$firstpassword.'&fee='.$fee.'&second_password='.$second_password.'&from=0';
$response = Curl::to($root_url . '?' . $parameters)->get();
return $response;
..........................
if you are using the php version found in github, you can set the from_address as follows
calling the function as follows:
$address = 'to-address';
$amount = 0.01;
$from = 0;
$fee = 0.00012;
$Blockchain->Wallet->send($address,$amount,$from,$fee);
where $fee is optional
Upvotes: 0
Reputation: 303
You can try this:
first thing, you have to make sure that the blockchain wallet services are running on your server on port 3000. You can check the working of blockchain wallet services by hitting the url in browser i.e. http://localhost:3000. if its giving response error "Not found" that means your blockchain wallet services are running. To send bitcoins to many users at a time, you can use the following API:
http://localhost:3000/merchant/$guid/sendmany?password=$main_password&second_password=$second_password&recipients=$recipients&fee=$fee
where $guid is your blockchain wallet ID, $main_password is your wallet first password, $second_password is your wallet's second password if you have turned the second password is ON, $recipients is your JSON object with receiving addresses as key and amount as values, $fee is transaction fee, which must be more than default transaction fee which is optional.
$recipients object will be like
{
"1JzSZFs2DQke2B3S4pBxaNaMzzVZaG4Cqh": 100000000,
"12Cf6nCcRtKERh9cQm3Z29c9MWvQuFSxvT": 1500000000,
"1dice6YgEVBf88erBFra9BHf6ZMoyvG88": 200000000
}
Upvotes: 1