Author

Topic: If you need help with blockchain API - HERE (Read 842 times)

member
Activity: 84
Merit: 10
March 20, 2014, 07:14:48 PM
#5
A very useful method waiting a official update from blockchain.
newbie
Activity: 24
Merit: 0
I am also thinking about creating a sandbox for blockchain, working on this site has been hard since i been needing to use faucets for btc to test with LOL. I am pretty new to this Bitcoin thing but been learning a lot since my client wants a few sites developed using bitcoins.
newbie
Activity: 24
Merit: 0
i am developing a site for a client and everything has worked perfectly for me, i was trying to use the get method displayed on BlockChain's API and it does not work at all... this post method works perfect every time.
legendary
Activity: 2338
Merit: 1204
The revolution will be digital
newbie
Activity: 24
Merit: 0
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:
        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 
"
"
;
        
        
//Decode and get value
        
$Balance json_decode($Balance);
        echo 
"Decoded Balance: " $Balance->balance;
        echo 
"
"
;
        

        
//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;
    }
}
?>
Jump to: