Author

Topic: Validate Bitcoin address thru web api or php (Read 9508 times)

donator
Activity: 1218
Merit: 1079
Gerald Davis
The code I posted is much faster than this, and does not need to connect to any other server (such as blockchain.info). Wink

The code you posted does not work with multisig P2SH addresses

Minor correction.  There actually is no "multisig addresses" just Pay2PubKeyHash addresses and Pay2ScriptHash addresses.  The code provided only properly handles the former.
legendary
Activity: 1190
Merit: 1001
The code I posted is much faster than this, and does not need to connect to any other server (such as blockchain.info). Wink

The code you posted does not work with multisig addresses
member
Activity: 110
Merit: 10
Sometimes speed is not an issue.
newbie
Activity: 17
Merit: 0
thanks, i figured it out myself using the blockchain json rpc api. Ill try that code you took the time to post also thanks.


Code:
require_once('jsonrpcphp/includes/jsonRPCClient.php');
/** SIMPLE BITCOIN JSON RPC PHP**/
 
$btc_connect = array("user" => "",            
            
"pass" =>   "",                   
            
"host" =>   "blockchain.info",                     
            
"port" =>   80);                        
 
 
//create an array with connection settings
 
$bitcoin = new jsonRPCClient("http://{$btc_connect['user']}:{$btc_connect['pass']}@{$btc_connect['host']}:{$btc_connect['port']}");

$address 'bitcoinaddress';
$isvalid $bitcoin->validateaddress($address);
if($isvalid['isvalid']) {
//Address valid
}
else{
echo '---------'.$address.'---------';
}
?>

The code I posted is much faster than this, and does not need to connect to any other server (such as blockchain.info). Wink
sr. member
Activity: 335
Merit: 250
thanks, i figured it out myself using the blockchain json rpc api. Ill try that code you took the time to post also thanks.


Code:
require_once('jsonrpcphp/includes/jsonRPCClient.php');
/** SIMPLE BITCOIN JSON RPC PHP**/
 
$btc_connect = array("user" => "",            
            
"pass" =>   "",                   
            
"host" =>   "blockchain.info",                     
            
"port" =>   80);                        
 
 
//create an array with connection settings
 
$bitcoin = new jsonRPCClient("http://{$btc_connect['user']}:{$btc_connect['pass']}@{$btc_connect['host']}:{$btc_connect['port']}");

$address 'bitcoinaddress';
$isvalid $bitcoin->validateaddress($address);
if($isvalid['isvalid']) {
//Address valid
}
else{
echo '---------'.$address.'---------';
}
?>

newbie
Activity: 17
Merit: 0

function checkAddress($address)
{
    
$origbase58 $address;
    
$dec "0";

    for (
$i 0$i strlen($address); $i++)
    {
        
$dec bcadd(bcmul($dec,"58",0),strpos("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",substr($address,$i,1)),0);
    }

    
$address "";

    while (
bccomp($dec,0) == 1)
    {
        
$dv bcdiv($dec,"16",0);
        
$rem = (integer)bcmod($dec,"16");
        
$dec $dv;
        
$address $address.substr("0123456789ABCDEF",$rem,1);
    }

    
$address strrev($address);

    for (
$i 0$i strlen($origbase58) && substr($origbase58,$i,1) == "1"$i++)
    {
        
$address "00".$address;
    }

    if (
strlen($address)%!= 0)
    {
        
$address "0".$address;
    }

    if (
strlen($address) != 50)
    {
        return 
false;
    }

    if (
hexdec(substr($address,0,2)) > 0)
    {
        return 
false;
    }

    return 
substr(strtoupper(hash("sha256",hash("sha256",pack("H*",substr($address,0,strlen($address)-8)),true))),0,8) == substr($address,strlen($address)-8);
}

?>

Here is a PHP function to validate a bitcoin address. Wink
sr. member
Activity: 335
Merit: 250
someone explain to me how to use the json rpc, with blockchains api. There is little to no documentation i want to stop wasting my time with this. Just help me.
kjj
legendary
Activity: 1302
Merit: 1025
You can do it without a bitcoind node.

Look up the base58check routines.  There are several PHP implementations available.  Basically, that is all a bitcoind node would do.  (If the address belonged to a known key, it would provide other info too, but that doesn't matter.)
sr. member
Activity: 335
Merit: 250
In PHP JSON-RPC you can use this code:

Code:
$isvalid = $bitcoin->validateaddress($address);
if($isvalid['isvalid']) {
//Address valid
}





how can that be used in on a website that dosnt have access to the bitcoin client


https://blockchain.info/api/json_rpc_api
i guess i can use this right?
legendary
Activity: 1582
Merit: 1002
In PHP JSON-RPC you can use this code:

Code:
$isvalid = $bitcoin->validateaddress($address);
if($isvalid['isvalid']) {
//Address valid
}
hero member
Activity: 616
Merit: 522
Not sure what you understand by “real”. This thread provides validation functions if various languages. You can only check if the address is valid. If by real you mean that someone is actually using this address (someone has a private key), then you can't know that.
sr. member
Activity: 335
Merit: 250
to see if its a real address
member
Activity: 110
Merit: 10
What do you mean by 'validate' exactly?
sr. member
Activity: 335
Merit: 250
I have a database of bitcoin addresses and i need to validate them. Please explain the process , i don't care if its an api or a script as long as its efficient.
Jump to: