Getting Hash160 bitcoin address in python

+1 vote

I'm trying to figure out, how transactions work in bitcoin.

When I choose inputs for a new tx I want to make sure they belong to a specific address. However, existing txs do not specify previous outputs' addresses, but instead they contain address's hash.

e.g.:

>> bx fetch-tx 11a1b7ac0a65bd50b7094c720aecd77cfd83d84b1707960fd00dd82a888aab5c --config /home/theo/Desktop/bx-testnet.cfg


{

    hash 11a1b7ac0a65bd50b7094c720aecd77cfd83d84b1707960fd00dd82a888aab5c

    inputs

    {

        input

        {

            address_hash f3b7278583827a049d6be894bf7f516178a0c8e6

            previous_output

            {

                hash 4a3532061d43086299ae9b2409a456bb9638dff32e0858c4ccda27203fb2e4f6

                index 1

            }

            script "[30440220146b8b5b014245a9e27e21122d4dded04c3f39c3a49ac2494743d6f6ae8efff602206d417a4be9c7431ea69699132438510ade1cf8d746607f77d114907762ed1eb301] [023dd2e892290e41bb78efce6ea30a97015ef13eaaa9ebb7b0514485fc365cc391]"

            sequence 4294967295

        }

    }

    lock_time 0

    outputs

    {

        output

        {

            address_hash a73706385fffbf18855f2aee2a6168f29dbb597e

            script "dup hash160 [a73706385fffbf18855f2aee2a6168f29dbb597e] equalverify checksig"

            value 130000000

        }

        output

        {

            address_hash ad6e80394af99ece5d7701bf2f457480b93965b7

            script "dup hash160 [ad6e80394af99ece5d7701bf2f457480b93965b7] equalverify checksig"

            value 49525957813

        }

    }

    version 1

}

What do to if I want to check which of the outputs can be sent from address mvm74FACaagz94rjWbNmW2EmhJdmEGcxpa 

So I take its Hash160 in Python:

>> hashlib.new('ripemd160', hashlib.sha256("mvm74FACaagz94rjWbNmW2EmhJdmEGcxpa".encode('utf-8')).digest()).hexdigest()

'748598cd9b004aecf8a2d97464fb1f2a90562ffe'

That is not the result I expected: a73706385fffbf18855f2aee2a6168f29dbb597e

How to get Hash160?

Aug 24, 2018 in Blockchain by digger
• 26,740 points
3,837 views

1 answer to this question.

0 votes
There is a package to decode and encode in base58 and it's called base58. You can install it using the following command:

python -m pip install base58

Then use this to get the ripemd160 hash of a bitcoin address coded in base58 (python 2.7):

>>>import base58

>>>adr58 = '1Q2TWHE3GMdB6BZKafqwxXtWAWgFt5Jvm3'

>>>adr160 = base58.b58decode_check(adr58).encode('hex')[2:]

>>>print (adr160)

fc916f213a3d7f1369313d5fa30f6168f9446a2d
answered Aug 24, 2018 by slayer
• 29,370 points

Related Questions In Blockchain

+2 votes
1 answer

how to convert hash160 to bitcoin address in python?

Hey @Raj. I use the following script. ...READ MORE

answered Jul 12, 2019 in Blockchain by Tanisha
3,735 views
0 votes
1 answer

Getting Bitcoin address from pubkey_hash

The unexpected result is due to encoding. For ...READ MORE

answered Aug 22, 2018 in Blockchain by digger
• 26,740 points
1,204 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
5,451 views
0 votes
1 answer

Creating bitcoin address in ruby

When you calculate the SHA256 checksum, make ...READ MORE

answered Aug 28, 2018 in Blockchain by slayer
• 29,370 points
761 views
+1 vote
1 answer

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

yes all are over TCP/IP connections secured ...READ MORE

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

Python request module for bitcoin json rpc

This should work: #!/usr/bin/env python import getpass import json import requests ...READ MORE

answered Aug 28, 2018 in Blockchain by digger
• 26,740 points
2,363 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,923 views
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 26,740 points
45,219 views
0 votes
1 answer

How are unique public address generated in bitcoin?

In brief, the public addresses are generated ...READ MORE

answered Jul 16, 2018 in Blockchain by slayer
• 29,370 points
771 views
0 votes
1 answer

How to generate Bitcoin address in Ruby?

In your generate_address_from_public_key_hash method, the checksum should be over ...READ MORE

answered Aug 22, 2018 in Blockchain by slayer
• 29,370 points
2,683 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP