Created
October 14, 2021 13:28
-
-
Save AdityaEXP/27408bd361d5b8fcc9ac2bf459eb5303 to your computer and use it in GitHub Desktop.
Send bitcoin from your coinbase email to another person email by php.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to check transaction status in php using api