Getting Hash160 bitcoin address in python

0 votes

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,550 points
481 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,170 points

Related Questions In Blockchain

+2 votes
1 answer
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,550 points
105 views
0 votes
1 answer

How to create Bitcoin Address in PHP?

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

answered Aug 27, 2018 in Blockchain by Perry
• 17,020 points
578 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,170 points
50 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 ariaholic
• 7,340 points
94 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,550 points
290 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
173 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,170 points
55 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,170 points
895 views