Bitcoin Forum
September 26, 2016, 12:16:30 PM *
News: Due to DDoS attacks, there may be periodic downtime.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: determine valid bitcoin address  (Read 4476 times)
mtgox
Full Member
***
Offline Offline

Activity: 185


View Profile WWW
November 19, 2010, 12:47:02 PM
 #1

Can someone point me to code somewhere that determines if a string is a valid bitcoin address?

1474892190
Hero Member
*
Offline Offline

Posts: 1474892190

View Profile Personal Message (Offline)

Ignore
1474892190
Reply with quote  #2

1474892190
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1474892190
Hero Member
*
Offline Offline

Posts: 1474892190

View Profile Personal Message (Offline)

Ignore
1474892190
Reply with quote  #2

1474892190
Report to moderator
davout
Legendary
*
Offline Offline

Activity: 1358


1davout


View Profile WWW
November 19, 2010, 12:56:18 PM
 #2

You get it for free as JSON-RPC call in new versions of the client.
Otherwise see https://github.com/davout/bitcoin-bank/blob/master/lib/bitcoin/util.rb which is a shameless port of some python bit of code I found lying around in the forums, if you find that thread i'll add some comment giving credit.

I would, however, rely on the JSON-RPC call now that it is implementes, gonna drop this snippet in favor of this simple call.

mtgox
Full Member
***
Offline Offline

Activity: 185


View Profile WWW
November 19, 2010, 01:06:09 PM
 #3

Yeah I wanted to do it in javascript. But I can just port this. Thanks.

davout
Legendary
*
Offline Offline

Activity: 1358


1davout


View Profile WWW
November 19, 2010, 01:52:16 PM
 #4

Yeah I wanted to do it in javascript. But I can just port this. Thanks.
You'll probably end up writing way less code and get upgrade/bugfixes for free with an Ajax call.

Gavin Andresen
Legendary
*
qt
Offline Offline

Activity: 1652


Chief Scientist


View Profile WWW
November 19, 2010, 03:55:34 PM
 #5

daveout's code isn't quite right (because he based it on an earlier version of my python code).

Corrected version of the python code is in this thread.

How often do you get the chance to work on a potentially world-changing project?
davout
Legendary
*
Offline Offline

Activity: 1358


1davout


View Profile WWW
November 19, 2010, 04:04:56 PM
 #6

daveout's code isn't quite right (because he based it on an earlier version of my python code).

Corrected version of the python code is in this thread.

Thank you for pointing it out!
I'll drop this piece of code anyway, I'd much rather rely on the bitcoin client implementation of the check.

Was fun to learn some Python while porting it to Ruby =)

theymos
Administrator
Legendary
*
expert
Offline Offline

Activity: 2422


View Profile
November 19, 2010, 04:10:23 PM
 #7

Here's my PHP version:
http://pastebin.com/vmRQC7ha

I have a web interface to that:
http://theymos.ath.cx:64150/q/checkaddress

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
mikegogulski
Sr. Member
****
Offline Offline

Activity: 360



View Profile WWW
November 21, 2010, 05:19:18 PM
 #8

Here's my PHP version:
http://pastebin.com/vmRQC7ha

Thanks for this, but checkAddress() appears to be broken for some addresses:

1F417eczAAbh41V4oLGNf3DqXLY72hsM73 bool(true)
12uJ8qf82vbD76JYxSC38wqXo6QpPdRWbh bool(true)
1F417eczAAbh41V4oLGNf3DqXLY72hsM7 bool(false)
1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD bool(true)
17NdbrSGoUotzeGCcMMCqnFkEvLymoou9j bool(true)
1MU97wyf7msCVdaapneW2dW1uXP7oEQsFA  bool(false) ** Actually valid ** Edit: I'm a dumbass, nevermind.
1N3QX79szMKAJm35NLRSfSpD9DmpQTbNLR bool(true)
1Jcbeg2VjLLJrVztBrsk2UgyEDeLPfk5Q bool(true)
1F417eczAAbh41V4oLGNf3DqXLY72hsM73 bool(true)
F417eczAAbh41V4oLGNf3DqXLY72hsM73 bool(false)
1417eczAAbh41V4oLGNf3DqXLY72hsM73 bool(false)
1F17eczAAbh41V4oLGNf3DqXLY72hsM73 bool(false)
1F4AAbh41V4oLGNf3DqXLY72hsM73 bool(false)
1F417eczAAbDqXLY72hsM73 bool(false)
1F417eczAAbh0000 bool(false)
1F417eczAAbhNf3DqXL72hsM73 bool(false)

[Edit:] This refers to the PHP version

FREE ROSS ULBRICHT, allegedly one of the Dread Pirates Roberts of the Silk Road
theymos
Administrator
Legendary
*
expert
Offline Offline

Activity: 2422


View Profile
November 21, 2010, 06:09:43 PM
 #9

Thanks for this, but checkAddress() appears to be broken for some addresses:

Those are all correct. Nothing can tell you whether someone actually owns an address. It simply checks that the address is in the correct form and contains a valid checksum.

Try to send bitcoins to any of the addresses you listed. Bitcoin will either prevent you from doing so if checkAddress() is false, or it will show a green checkmark if checkAddress() is true.

Quote
1MU97wyf7msCVdaapneW2dW1uXP7oEQsFA  bool(false) ** Actually valid **

I just tested this and checkAddress() returned true. Maybe you had some spaces or something: it does no "cleanup" at all.

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
lfm
Full Member
***
Offline Offline

Activity: 196



View Profile
November 21, 2010, 11:06:23 PM
 #10

You should probably have some test cases both good and bad with multiple leading "1"s. They are valid and part of the error checking in some cases.

for instance :

11111111111111111111114oLvT2 bad
1111111111111111111114oLvT2 good
111111111111111111114oLvT2 bad

mikegogulski
Sr. Member
****
Offline Offline

Activity: 360



View Profile WWW
November 22, 2010, 02:35:49 AM
 #11

Thanks for this, but checkAddress() appears to be broken for some addresses:

Those are all correct.

Quote
1MU97wyf7msCVdaapneW2dW1uXP7oEQsFA  bool(false) ** Actually valid **

I just tested this and checkAddress() returned true. Maybe you had some spaces or something: it does no "cleanup" at all.

Okay, now I feel like a jackass. Somehow a space snuck itself in to the end of that string.

Sorry. Thanks for the function! I'm going to incorporate it into what I'm doing.

Peace,
Mike

FREE ROSS ULBRICHT, allegedly one of the Dread Pirates Roberts of the Silk Road
bitcoinex
Sr. Member
****
Offline Offline

Activity: 350


probiwon.com


View Profile WWW
November 23, 2010, 02:11:52 AM
 #12

Thanks for this, but checkAddress() appears to be broken for some addresses:

Those are all correct.

Quote
1MU97wyf7msCVdaapneW2dW1uXP7oEQsFA  bool(false) ** Actually valid **

I just tested this and checkAddress() returned true. Maybe you had some spaces or something: it does no "cleanup" at all.

Okay, now I feel like a jackass. Somehow a space snuck itself in to the end of that string.

Sorry. Thanks for the function! I'm going to incorporate it into what I'm doing.

Peace,
Mike

This topic contains an explanation of why is undesirable to use such functions:
https://www.bitcoin.org/smf/index.php?topic=1267.msg13897

New bitcoin lottery: probiwon.com
- Может, ты ещё и в Невидимую Руку Рынка веруешь? - Зачем же веровать в то, что можно наблюдать непосредственно?
theymos
Administrator
Legendary
*
expert
Offline Offline

Activity: 2422


View Profile
November 23, 2010, 02:39:24 AM
 #13

This topic contains an explanation of why is undesirable to use such functions:
https://www.bitcoin.org/smf/index.php?topic=1267.msg13897

If something changes in Bitcoin, then all old Bitcoin clients will also screw up. My PHP code checks the address version number in the same way as Bitcoin, so it should be future-proof.

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
mikegogulski
Sr. Member
****
Offline Offline

Activity: 360



View Profile WWW
November 23, 2010, 06:29:34 AM
 #14

This topic contains an explanation of why is undesirable to use such functions:
https://www.bitcoin.org/smf/index.php?topic=1267.msg13897

As theymos writes, versioning can be taken care of with a check.

Additionally, I want verification of an address's validity external to the bitcoind I'm talking to because I do not want to hand bogus addresses generated by a malfunctioning or impostor bitcoind over to customers as payment addresses. And, since I'm not talking to it with a regular bitcoin client, I can't use those functions.

FREE ROSS ULBRICHT, allegedly one of the Dread Pirates Roberts of the Silk Road
dduane
Jr. Member
*
Offline Offline

Activity: 47



View Profile WWW
December 19, 2010, 07:30:54 AM
 #15

Here's my PHP version:
http://pastebin.com/vmRQC7ha

I have a web interface to that:
http://theymos.ath.cx:64150/q/checkaddress

Thanks for this, I'm working on a Drupal module to accept Bitcoin addresses as a CCK field type and validate them with this. 

--Darrell
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!