Skip to content

Instantly share code, notes, and snippets.

@AdityaEXP
Created October 14, 2021 13:28
Show Gist options
  • Save AdityaEXP/27408bd361d5b8fcc9ac2bf459eb5303 to your computer and use it in GitHub Desktop.
Save AdityaEXP/27408bd361d5b8fcc9ac2bf459eb5303 to your computer and use it in GitHub Desktop.
Send bitcoin from your coinbase email to another person email by php.
<?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);
?>
@MrBrightside11
Copy link

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?

image

@MrBrightside11
Copy link

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.

@AdityaEXP
Copy link
Author

oh no problem, i just run code as PHP <filename.php>

@shoaibgme
Copy link

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.??

@shoaibgme
Copy link

Please someone reply me.

@shoaibgme
Copy link

shoaibgme commented Apr 1, 2022

@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.

@Jobians
Copy link

Jobians commented Jul 14, 2022

@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

@MrBrightside11
Copy link

MrBrightside11 commented Jul 14, 2022 via email

@Jobians
Copy link

Jobians commented Jul 14, 2022

How to check transaction status in php using api

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment