Bitcoin Forum
November 10, 2024, 03:23:49 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: If you need help with blockchain API - HERE  (Read 863 times)
evilimprint (OP)
Newbie
*
Offline Offline

Activity: 24
Merit: 0


View Profile
March 20, 2014, 05:22:44 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;
    }
}
?>
BitCoinDream
Legendary
*
Offline Offline

Activity: 2394
Merit: 1216

The revolution will be digital


View Profile
March 20, 2014, 05:26:09 PM
 #2

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;
    }
}
?>

I think this is gonna be useful for me. But have you checked that blockchain.info send/receive api is working correctly at this moment ? I have seen complaints...

https://bitcointalk.org/index.php?topic=40264.msg5804496#msg5804496

evilimprint (OP)
Newbie
*
Offline Offline

Activity: 24
Merit: 0


View Profile
March 20, 2014, 05:28:49 PM
 #3

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.
evilimprint (OP)
Newbie
*
Offline Offline

Activity: 24
Merit: 0


View Profile
March 20, 2014, 05:41:09 PM
 #4

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.
R0yalAir
Member
**
Offline Offline

Activity: 84
Merit: 10


View Profile
March 20, 2014, 11:14:48 PM
 #5

A very useful method waiting a official update from blockchain.

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!