Bitcoin Forum
May 06, 2024, 06:16:17 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Validate Bitcoin address thru web api or php  (Read 9507 times)
likl3sfuhjh (OP)
Sr. Member
****
Offline Offline

Activity: 335
Merit: 250


View Profile
May 06, 2013, 11:41:21 PM
 #1

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.

Where do I get free bitcoins?
www.bitcoinforest.com - Bitcoin faucet and survey site. Get .001 bitcoins for each survey, and .00001 for each captcha.
1715019377
Hero Member
*
Offline Offline

Posts: 1715019377

View Profile Personal Message (Offline)

Ignore
1715019377
Reply with quote  #2

1715019377
Report to moderator
The Bitcoin software, network, and concept is called "Bitcoin" with a capitalized "B". Bitcoin currency units are called "bitcoins" with a lowercase "b" -- this is often abbreviated BTC.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715019377
Hero Member
*
Offline Offline

Posts: 1715019377

View Profile Personal Message (Offline)

Ignore
1715019377
Reply with quote  #2

1715019377
Report to moderator
minzie
Member
**
Offline Offline

Activity: 110
Merit: 10



View Profile WWW
May 06, 2013, 11:46:09 PM
 #2

What do you mean by 'validate' exactly?

Professional Freelance Web Apps Engineer ° Portfolio °  ModoBot Automated Trading Platform ° BitThingy ° My Github  ° Skype: cclites_1
likl3sfuhjh (OP)
Sr. Member
****
Offline Offline

Activity: 335
Merit: 250


View Profile
May 06, 2013, 11:47:18 PM
 #3

to see if its a real address

Where do I get free bitcoins?
www.bitcoinforest.com - Bitcoin faucet and survey site. Get .001 bitcoins for each survey, and .00001 for each captcha.
Terk
Hero Member
*****
Offline Offline

Activity: 616
Merit: 522



View Profile
May 06, 2013, 11:53:10 PM
 #4

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.

giantdragon
Legendary
*
Offline Offline

Activity: 1582
Merit: 1002



View Profile
May 07, 2013, 12:16:35 AM
 #5

In PHP JSON-RPC you can use this code:

Code:
$isvalid = $bitcoin->validateaddress($address);
if($isvalid['isvalid']) {
//Address valid
}
likl3sfuhjh (OP)
Sr. Member
****
Offline Offline

Activity: 335
Merit: 250


View Profile
May 07, 2013, 03:41:11 AM
 #6

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?

Where do I get free bitcoins?
www.bitcoinforest.com - Bitcoin faucet and survey site. Get .001 bitcoins for each survey, and .00001 for each captcha.
kjj
Legendary
*
Offline Offline

Activity: 1302
Merit: 1024



View Profile
May 07, 2013, 03:52:07 AM
 #7

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.)

17Np17BSrpnHCZ2pgtiMNnhjnsWJ2TMqq8
I routinely ignore posters with paid advertising in their sigs.  You should too.
likl3sfuhjh (OP)
Sr. Member
****
Offline Offline

Activity: 335
Merit: 250


View Profile
May 07, 2013, 04:29:58 AM
 #8

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.

Where do I get free bitcoins?
www.bitcoinforest.com - Bitcoin faucet and survey site. Get .001 bitcoins for each survey, and .00001 for each captcha.
robin0van0der0vliet
Newbie
*
Offline Offline

Activity: 17
Merit: 0


View Profile WWW
May 07, 2013, 12:19:28 PM
 #9

<?php

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
likl3sfuhjh (OP)
Sr. Member
****
Offline Offline

Activity: 335
Merit: 250


View Profile
May 07, 2013, 09:42:53 PM
 #10

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:
<?php
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.'---------';
}
?>


Where do I get free bitcoins?
www.bitcoinforest.com - Bitcoin faucet and survey site. Get .001 bitcoins for each survey, and .00001 for each captcha.
robin0van0der0vliet
Newbie
*
Offline Offline

Activity: 17
Merit: 0


View Profile WWW
May 08, 2013, 08:42:59 PM
 #11

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:
<?php
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
minzie
Member
**
Offline Offline

Activity: 110
Merit: 10



View Profile WWW
May 09, 2013, 01:04:10 AM
 #12

Sometimes speed is not an issue.

Professional Freelance Web Apps Engineer ° Portfolio °  ModoBot Automated Trading Platform ° BitThingy ° My Github  ° Skype: cclites_1
dave111223
Legendary
*
Offline Offline

Activity: 1190
Merit: 1001


View Profile WWW
July 15, 2014, 04:28:44 PM
 #13

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
DeathAndTaxes
Donator
Legendary
*
Offline Offline

Activity: 1218
Merit: 1079


Gerald Davis


View Profile
July 15, 2014, 10:32:25 PM
 #14

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.
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!