An official PHP library for interacting with the blockchain.info API.
Download the source or clone the repository. Copy the lib/
folder into your project and add:
require('lib/Blockchain.php');
$Blockchain = new Blockchain();
All functionality is provided through the Blockchain
object.
###Call Limits
The official documentation lists API call limits, which may be bypassed with an API code. If you use a code, enter it when you create the Blockchain
object:
$Blockchain = new Blockchain($my_api_code);
If you need an API code, you may request one here.
###Network Timeouts
Set the cURL
timeout, in seconds, with the setTimeout
member function:
$Blockchain->setTimeout($timeout_seconds);
The default network timeout is 60
seconds.
All Bitcoin values returned by the API are in string float format, in order to preserve full value precision. It is recommended that all arithmetic operations performed on Bitcoin values within PHP utilize the bcmath
functions as follows:
#####bcadd
Add Two Numbers
$result = bcadd("101.234115", "34.92834753", 8); // "136.16246253"
#####bcsub
Subtract Two Numbers
$result = bcsub("101.234115", "34.92834753", 8); // "66.30576747"
#####bcmul
Add Two Numbers
$result = bcmul("101.234115", "34.92834753", 8); // "3535.940350613"
#####bcdiv
Add Two Numbers
$result = bcdiv("101.234115", "34.92834753", 8); // "2.89833679"
The 8
in the final parameter of each bcmath
function call represents the numerical precision to keep in the result.
More help on the bcmath
functions can be found in the PHP BC Math documentation.
Block explorer - Access details of the Bitcoin blockchain
Create Wallets - Create new Blockchain wallets
Exchange Rates - See the value of Bitcoin relative to world currencies
Push Transaction - Push raw transactions to the Bitcoin network
Receive - The easiest way to accept Bitcoin payments
Statistics - Bitcoin network statistics
Wallet - Send and receive Bitcoin programmatically
The library depends on having the curl
and bcmath
modules enabled in your PHP installation.