PHP - Validate Multisig Bitcoin Wallet Address with Leading 2 or 3

0 votes

I have used this function for validating the bitcoin wallet address to see if it's a bitcoin address. However, it's not working with the address that starts with "3" (multi-sig). For example, 3EktnHQD7RiAE6uzMj2ZifT9YgRrkSgzQX.

Can anyone help me with that function to make it work so that it can validate all major forms of bitcoin wallet addresses?

Apr 7 in Blockchain by Rahul
• 9,240 points
408 views

1 answer to this question.

0 votes

 The answer to your question is located here

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();

Hope this clarifies your doubt. 

answered Apr 11 by Soham
• 9,330 points

Related Questions In Blockchain

+3 votes
3 answers

How to validate bitcoin address?

I found these 2 scripts online: Javascript: <html> <head> <script type="text/javascript" ...READ MORE

answered Aug 17, 2018 in Blockchain by slayer
• 29,310 points
4,199 views
0 votes
1 answer

How to open bitcoin-qt wallet with bitcoinj?

I found this issue solved at the ...READ MORE

answered Aug 24, 2018 in Blockchain by slayer
• 29,310 points
354 views
0 votes
1 answer

How to create Bitcoin Address in PHP?

You need to understand that Bitcoin address and ...READ MORE

answered Aug 28, 2018 in Blockchain by Perry
• 17,100 points
3,922 views
0 votes
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured by TLS encryption in hashgraph architecture-hashgraph, ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,440 points
673 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,044 views
0 votes
1 answer
0 votes
1 answer

Get amount of Bitcoins at an address with PHP

While checking the Coinbase address balance, the ...READ MORE

answered Feb 28 in Blockchain by Soham
• 9,330 points
58 views
0 votes
1 answer

Know which exchange or wallet is behind a BTC address?

To answer your question, due to each ...READ MORE

answered Feb 28 in Blockchain by Soham
• 9,330 points
1,070 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP