Title: Re: Validate Bitcoin address thru web api or php Post by: dhavin on August 17, 2016, 03:03:57 AM 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 I don't mean to resurrect a dead post, but this API is no longer working. Can someone link me to the current replacement API? Blockchain is driving me nuts. Or any alternative way to validate a BTC address that will catch all addresses.. that would also be awesome. Title: Re: Validate Bitcoin address thru web api or php Post by: fbueller on August 18, 2016, 09:44:43 PM I maintain `bitwasp/bitcoin`which is available through composer. It lets you do quite a lot, and no bitcoind required. https://github.com/Bit-Wasp/bitcoin-php/blob/master/src/Address/AddressFactory.php#L87 contains the function to check an address.
Title: Re: Validate Bitcoin address thru web api or php Post by: coinableS on August 19, 2016, 04:46:27 AM The script on rosettacode works. Also it provides examples to validate bitcoin addresses in 20 different languages.
https://rosettacode.org/wiki/Bitcoin/address_validation#PHP Code: function validate($address){ Title: Re: Validate Bitcoin address thru web api or php Post by: fikihafana on August 21, 2016, 03:08:27 AM 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. you can use several methods such as using api or create your own rpc daemon. Both of this have advantage and disadvantage . I think it's very simple and efficient. another way you can use this Quote function validate($address){ $decoded = decodeBase58($address); $d1 = hash("sha256", substr($decoded,0,21), true); $d2 = hash("sha256", $d1, true); if(substr_compare($decoded, $d2, 21, 4)){ throw new \Exception("bad digest"); } return true; } function decodeBase58($input) { $alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; $out = array_fill(0, 25, 0); for($i=0;$i<strlen($input);$i++){ if(($p=strpos($alphabet, $input[$i]))===false){ throw new \Exception("invalid character found"); } $c = $p; for ($j = 25; $j--; ) { $c += (int)(58 * $out[$j]); $out[$j] = (int)($c % 256); $c /= 256; $c = (int)$c; } if($c != 0){ throw new \Exception("address too long"); } } $result = ""; foreach($out as $val){ $result .= chr($val); } return $result; } function main () { $s = array( "1Q1pE5vPGEEMqRcVRMbtBK842Y6Pzo6nK9", "1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i", "1Q1pE5vPGEEMqRcVRMbtBK842Y6Pzo6nJ9", "1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62I", ); foreach($s as $btc){ $message = "OK"; try{ validate($btc); }catch(\Exception $e){ $message = $e->getMessage(); } echo "$btc: $message\n"; } } main(); Title: Re: Validate Bitcoin address thru web api or php Post by: Anduck on August 21, 2016, 02:28:41 PM You can use PHPs exec-function to call bitcoin-cli validateaddress. Or you can use JSON-RPC php library to do the same.
Title: Re: Validate Bitcoin address thru web api or php Post by: konovalets on August 22, 2016, 07:19:27 PM You can use PHPs exec-function to call bitcoin-cli validateaddress. Or you can use JSON-RPC php library to do the same. It's not very good choice if you need to check big database of addresses. Validation is a simple process and it was implemented with all major languages. So it's much faster to get addresses list from db and validate them locally. |