Bitcoin Forum
June 24, 2024, 10:44:32 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: BlockChain API - PHP HERE  (Read 550 times)
evilimprint (OP)
Newbie
*
Offline Offline

Activity: 24
Merit: 0


View Profile
March 20, 2014, 09:05:20 PM
 #1

Here is something to get you started if you were having issues with sendmany and other API calls at block chain

Accepting Donations: 1Lux3FWAAoNGHA7Hm1JNuBEuKjsTkezBf9

Code:
<?php
        define
'GUID''USER ID HERE');
        
define'FPASSWORD''FIRSTPASSWORD HERE');
        
define'SPASSWORD''SECOND PASSWORD HERE');
        
        
// Examples
        //Get Balance
        
$BlockChain = new BlockChain;
        
        
//Will return json_encoded array
        
$Balance $BlockChain->BlockChainAPI('balance');
        echo 
"Encoded Balance: " $Balance;
        echo 
"<BR>";
        
        
//Decode and get value
        
$Balance json_decode($Balance);
        echo 
"Decoded Balance: " $Balance->balance;
        echo 
"<BR>";
        

        
//SendMany
        //Array = 'Address' => 'BTCAmount converted to Satoshi'
        
$Addresses = Array('1Lux3FWAAoNGHA7Hm1JNuBEuKjsTkezBf9' => '10000000''1Lux3FWAAoNGHA7Hm1JNuBEuKjsTkezBf9' => '10000000');
        
$SendMany $BlockChain->BlockChainAPI('sendmany'$Addresses);
        echo 
"Encoded send many return: " $SendMany;
        
// Decode and get value
        
$SendMany json_decode($SendMany);
        echo 
"Message: " $SendMany->message;
        echo 
"Error: " $SendMany->error;
        
        
        
//Generating a new address
        
$RandomLabel "Get btc address";
        
$Address $BlockChain->BlockChainAPI('new_address', array('label' => "$RandomLabel"));
        
//Return json_encoded Array
        
echo "Encoded Address: " $Address;
        
        
// Decode Address
        
$Address json_decode($Address);
        echo 
"New Address: " $Address->address;
        echo 
"Label for Address: " $Address->label;
        
        
        
Class 
BlockChain{
    function 
BlockChainAPI($Param$Param1 null) {
// API settings
static $ch null;
if (is_null($ch)) {
    $ch curl_init();
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
    curl_setopt($chCURLOPT_USERAGENT'Mozilla/4.0 (compatible; BlockChain PHP client;)');
}
curl_setopt($chCURLOPT_URL"https://blockchain.info/merchant/" GUID "/$Param?password=" .FPASSWORD "&second_password=" SPASSWORD);
        
        if(
$Param1){
            
$data http_build_query($Param1);
            
curl_setopt($chCURLOPT_POSTFIELDS$data);
        }
        
curl_setopt($chCURLOPT_SSL_VERIFYPEERFALSE);
$Return curl_exec($ch);
return $res;
    }
}
?>

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!