-
-
Save AdityaEXP/27408bd361d5b8fcc9ac2bf459eb5303 to your computer and use it in GitHub Desktop.
<?php | |
function sendTransaction($private_key, $api_key , $to_email , $amount , $currency, $URL, $account_id){ | |
$json = new stdClass(); | |
$json->method = "POST"; | |
$json->path = "/v2/accounts/".$account_id."/transactions"; | |
$json->secretapikey = $private_key; | |
$json->apikey = $api_key; | |
$body = new stdClass(); | |
$body->type = "send"; | |
$body->to = $to_email; | |
$body->amount = $amount; | |
$body->currency = $currency; | |
$result = json_encode($json); | |
$body = json_encode($body); | |
$time= time(); | |
$sign = $time.$json->method.$json->path.$body; | |
$hmac = hash_hmac("SHA256", $sign, $json->secretapikey); | |
$header = array( | |
"CB-ACCESS-KEY:".$api_key, | |
"CB-ACCESS-SIGN:".$hmac, | |
"CB-ACCESS-TIMESTAMP:".time(), | |
"CB-VERSION:2019-11-15", | |
"Content-Type:application/json" | |
); | |
$ch = curl_init($URL); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $body); | |
curl_setopt($ch, CURLOPT_HTTPHEADER,$header); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
$result = curl_exec($ch); | |
curl_close($ch); | |
return $result; | |
}; | |
//Creating URL For Sending Request | |
$account_id = '8fde3e0a-xxxxxxx'; //Coinbase Account ID | |
$private_key = 'Doadlraixxxxxx'; //Coinbase Private Key | |
$api_key = 'ysEZjjBxxxxx'; //Coinbase API KEY | |
$to_email = 'xxxxx@gmail.com'; //Reciver Email | |
$amount = 0.000001; //Amount To Send | |
$currency = 'BTC'; //Crypto To Send | |
$url = "https://api.coinbase.com/v2/accounts/".$account_id."/transactions"; | |
$tranx_id = sendTransaction( | |
$private_key, | |
$api_key, | |
$to_email, | |
$amount, | |
$currency, | |
$url, | |
$account_id | |
); | |
print_r($tranx_id); | |
?> |
Hi! I got your code working mostly on my site. I am running into an issue where it seems to always double send payments to users.
I have tried both LTC and BTC payments, and always there is a double send. Any ideas?
can you explain more with photos etc?
Sure. I have your above API coded on a .php file. I run it in my web browser to process the API.
If I put an actual BTC or LTC address in where it says "$to_email = 'xxxxx@gmail.com'; //Reciver Email", it processes the transaction fine.
I just discovered this yesterday.
However, if I put a user's email (no matter what user), it always sends the payment twice for some reason. It sends it, and then sends it again.
The attached image shows 2 API calls, each which ended up with a duplicate payment.
I even tried to add the "idem" parameter on the API call to ensure it was unique, but that was to no avail.
I noticed the API version has been updated on Coinbase, but I still used the version you had in your code here:
"CB-VERSION:2019-11-15",
Anyhow, not sure what is causing the double pay.
hmm, I tested the code before it send transactions only one time & there is no issue with the API version. i will test it again
Weird, well maybe there is something not in the code. Like maybe because I ran mine online through my website, it ran twice when interacting with Coinbase email addresses? It looks like you are running yours on a command prompt? What program are you running to edit / run the file?
Also, maybe it is one of the API permissions I have checked causing it to double send. I checked them all. Are there ones you don't have checked?
I think I figured out the issue. For some reason, it auto refreshes and runs the call twice. If I put a timer in, the 2nd call I can manually block.
Also, my idempotent variable I was passing in, most likely is doing nothing, since the time is differing by a some milliseconds, so it looks like two unique calls.
oh no problem, i just run code as PHP <filename.php>
i am getting problem while sending money through this code and getting error message.
{"errors":[{"id":"not_found","message":"Not found"}]}
Can someone plz guide me how i can get the account id from coinbase account please its urgent.??
Please someone reply me.
@MrBrightside11 can you please tell me how to get the account id mentioned in url of code:
$url = "https://api.coinbase.com/v2/accounts/".$account_id."/transactions";
its urgent please.
@MrBrightside11 can you please tell me how to get the account id mentioned in url of code:
$url = "https://api.coinbase.com/v2/accounts/".$account_id."/transactions";
its urgent please.
Click https://www.coinbase.com/home
Screenrecording_20220714_154019.mp4
How to check transaction status in php using api
Good !!, Working