What is BlockChain?
The blockchain is basically an Application Programming Interface (API) a mediator like a wallet which is used to send the payments to the users or another person. Blockchain generates the unique address ( BoatSLRHtKNngkdXEeobR76b53LETtpyT ) for payments to different users. So, in short, the addresses generated are the identifiers which are used to send bitcoins to another person.
1. Steps:
Create a file index.php
Code:
Code:
<?php $api_key = "your_blockchain_api_Key"; $xpub = "xpubYour_extended_public_key"; $secret = "your_secret"; //this can be anything you want $rootURL = "http://yourrooturl.com/directory"; //example https://mysite.org or http://yourhomepage.com/store $orderID = uniqid(); //call blockchain info receive payments API $callback_url = $rootURL."/callback.php?invoice=".$orderID."&secret=".$secret ; $receive_url = "https://api.blockchain.info/v2/receive?key=".$api_key."&xpub=".$xpub."&callback=" .urlencode($callback_url); $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, $receive_url); $ccc = curl_exec($ch); $json = json_decode($ccc, true); $payTo = $json['address']; //the newly created address will be stored under 'address' in the JSON response echo $payTo; //echo out the newly created receiving address ?>
Code:
<?php $secret = "abc123"; if($_GET['secret'] != $secret){ die('stop doing that'); } else { $fff =fopen("test.txt","w"); $value = $_GET['value']." - "; $fw =fwrite($fff, $value); $txhash =$_GET['transaction_hash']." - "; $fw =fwrite($fff, $txhash); $invoice = $_GET['invoice']; $fw =fwrite($fff, $invoice); fclose($fff); echo "*ok*"; } ?>
- Click on this link: https://blockchain.info/api/
- See below screenshot:
Click on view documentation.
- See below screenshot:
- Click on “Please create an API code here including permissions to "Create Wallets""
- See below screenshot
- Fill out this form.
- An activation link will appear on your email id. As soon as we verify our email id the api key will be generated within 2-3 business days and the api key will appear on our email id.
4. To generate Extended Public Key (xPub)
- Click on this link: https://blockchain.info/
- Refer below screenshot:
- Click on Get a free wallet.
- Refer below screenshot:
- Fill out the information and then a verification email will be sent in your inbox along with the wallet ID.
- Then click on login button type the wallet ID which have been sent on your email id and type the password.
- Click on Settings -> Expand Settings -> Addresses
- Click on Manage -> More Options -> Show xPub
- Click on Continue Button then an xpub key will be there.
5. Then upload the code which is index.php and then type the url in your browser
i.e. yourrooturl.com/directory then an address will be generated.
Such kind of address will get generated everytime we refresh the page.
6. Then upload the 2nd file which is callback.php and then type the url in your browser as :
https://blockchain.info/address/url of address which is generated in yourrooturl.com/directory.
Then such kind of page occurs where we have scan the QR-code generator.
For testing purpose:
We can install bitpay on our mobile-device and a QR-scan option is there scan the QR-code.
It will provide us with the option like:
- Pay amount so we have to select the option of the payment amount and send the transaction to that particular address.
This how we can mass payout payment through Blockchain API.