Skip to content

Instantly share code, notes, and snippets.

@coinables
Created May 3, 2018 02:15
Show Gist options
  • Save coinables/39e5595b0d95185a7bd7a2e14308bbee to your computer and use it in GitHub Desktop.
Save coinables/39e5595b0d95185a7bd7a2e14308bbee to your computer and use it in GitHub Desktop.
coinpayments api generate new address example
<?php
// This example will create a new deposit address for a desired currency
// Link to the related documentation https://www.coinpayments.net/apidoc-get-deposit-address
////////////////////////////////////////////////////
// Fill these in from your API Keys page
$public_key = '';
$private_key = '';
// Note there are two required post fields "cmd" and "currency" per the above referenced documentation
// version, key and format will stay the same for all your requests.
$req['version'] = 1;
$req['cmd'] = "get_deposit_address";
$req['currency'] = "BTC";
$req['key'] = $public_key;
$req['format'] = 'json'; //supported values are json and xml
// Generate the query string
$post_data = http_build_query($req, '', '&');
// Calculate the HMAC signature on the POST data
$hmac = hash_hmac('sha512', $post_data, $private_key);
// Use curl to hit the endpoint so that you can send the required headers
$ch = curl_init('https://www.coinpayments.net/api.php');
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('HMAC: '.$hmac));
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
// Execute the call and close cURL handle
$data = curl_exec($ch);
// dump the data returned back from coinpayments
var_dump($data);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment