<p>I think I found solution to problem.. if someone will find it helpful, to get senders address for python:</p>

<pre><code>import json
import bitcoinrpc
conn = bitcoinrpc.connect_to_remote('username', 'password', host='127.0.0.1', port=9332)
accounts=conn.listaccounts()
for a in accounts:
        name=json.dumps(a)
        name = name[1:-1]

        #print name
        tran=conn.listtransactions(name)
        for t in tran:
            act=t
            txid=t.txid
            raw=conn.getrawtransaction(txid,0)
            dec=conn.decoderawtransaction(raw)
            vin=dec['vin'][0]['txid']
            raw=conn.getrawtransaction(vin,0)
            dec=conn.decoderawtransaction(raw)
            vout=dec['vout']
            print json.dumps(vout[0]['scriptPubKey']['addresses'])[2:-2]
</code></pre>

<p>also, in config add <strong>txindex=1</strong> and run <strong>litecoind -reindex</strong> from cmdline</p>

CC BY-SA 3.0
2014-04-23T19:45:26.200Z
props for C# snippet, inspirational.
Timo Junolainen
CC BY-SA 3.0
2014-04-23T19:39:05.067Z
2014-04-23T19:39:05.067Z
Timo Junolainen
<p>Sorry, i guess i misunderstood your question:
You have to encode the ripemd160 to base58 as you can see <a href="http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html" rel="nofollow">here</a></p>

<pre><code>def pubKeyToAddr(s):
  ripemd160 = hashlib.new('ripemd160')
  ripemd160.update(hashlib.sha256(s.decode('hex')).digest())
  return utils.base58CheckEncode(0, ripemd160.digest())
</code></pre>

<p>Anyway, you can always check <a href="https://en.bitcoin.it/wiki/Technical_background_of_Bitcoin_addresses" rel="nofollow">the details</a> of how to construct address.<br>
Aditionaly, if you want to use the <a href="https://en.bitcoin.it/wiki/Testnet" rel="nofollow">testnet</a>, remember to replace the first char from 0 to 0x6F like this</p>

<pre><code>  return utils.base58CheckEncode(0x6F, ripemd160.digest())
</code></pre>

CC BY-SA 3.0
2014-04-23T16:24:19.683Z
2014-04-28T13:54:20.860Z
2014-04-28T13:54:20.860Z
reiven
<p>Getting senders account</p>

<p>Say we got txid by <em>listtransactions</em>:</p>

<p><strong>"txid" : "2ca54b92338e52bbb16562dd7a91e8670d9362bb255e21fb568acc13e732b6b7"</strong></p>

<p>then</p>

<p><em>getrawtransaction 2ca54b92338e52bbb16562dd7a91e8670d9362bb255e21fb568acc13e732b6b7</em></p>

<p>and </p>

<p><em>decoderawtransaction 0100000001b2314a1f3d2552d781836cbf266b558eea31fb9f6b0e6da9340ab12e8760df0b000000006b483045022100dab5b2ef5e5be67fc0421c637c60a3d21064bcc7afe69f86909d0a7f91ae99440220762ad9a1d9c20a22378136e5653c2e7134499d1ac0ed86aba883faa7fbf6753f012102f342968588796d7214e189a6fef024bad4f29e7a155c93182a8b6f579b2c1fb2ffffffff02172e0100000000001976a914dc05a2f50f5ae09df42f584f5a5582891a41665088ac2e2f4100000000001976a914380e50d59602e9f9960f893f6f2c0f6eb7791b6088ac00000000</em></p>

<p>out of which we finally receive:</p>

<p><strong>"asm" : "3045022100dab5b2ef5e5be67fc0421c637c60a3d21064bcc7afe69f86909d0a7f91ae99440220762ad9a1d9c20a22378136e5653c2e7134499d1ac0ed86aba883faa7fbf6753f01 02f342968588796d7214e189a6fef024bad4f29e7a155c93182a8b6f579b2c1fb2"</strong></p>

<p>So far so good. Last part is publickey, if understand correctly:<strong>02f342968588796d7214e189a6fef024bad4f29e7a155c93182a8b6f579b2c1fb2</strong>, which can be translated to address</p>

<p>Then I do following in python to get senders address:
    import hashlib</p>

<pre><code>pkey="02f342968588796d7214e189a6fef024bad4f29e7a155c93182a8b6f579b2c1fb2"

ripemd160 = hashlib.new('ripemd160')

ripemd160.update(hashlib.sha256(pkey.decode('hex')).digest())
</code></pre>

<p>but ripemd160.hexdigest() returns 8cdd1b71d32e53a9fe326212281a4a99a1c093a8, and thats not what i want.</p>

<p>It should return valid address, and result seems a bit off to me. I think .hexdigest is wrong way to do it, should be converted to base58.</p>

<p>How properly convert ripemd160.digest into account address?</p>

<p>Thanks a lot</p>

<address><development><base58>
Getting sender address, python
Timo Junolainen
# Getting sender address, python

(Asked by: username_0 on 2014-04-23)

Getting senders account

Say we got txid by *listtransactions*:

**"txid" : "2ca54b92338e52bbb16562dd7a91e8670d9362bb255e21fb568acc13e732b6b7"**

then

*getrawtransaction 2ca54b92338e52bbb16562dd7a91e8670d9362bb255e21fb568acc13e732b6b7*

and

*decoderawtransaction 0100000001b2314a1f3d2552d781836cbf266b558eea31fb9f6b0e6da9340ab12e8760df0b000000006b483045022100dab5b2ef5e5be67fc0421c637c60a3d21064bcc7afe69f86909d0a7f91ae99440220762ad9a1d9c20a22378136e5653c2e7134499d1ac0ed86aba883faa7fbf6753f012102f342968588796d7214e189a6fef024bad4f29e7a155c93182a8b6f579b2c1fb2ffffffff02172e0100000000001976a914dc05a2f50f5ae09df42f584f5a5582891a41665088ac2e2f4100000000001976a914380e50d59602e9f9960f893f6f2c0f6eb7791b6088ac00000000*

out of which we finally receive:

**"asm" : "3045022100dab5b2ef5e5be67fc0421c637c60a3d21064bcc7afe69f86909d0a7f91ae99440220762ad9a1d9c20a22378136e5653c2e7134499d1ac0ed86aba883faa7fbf6753f01 02f342968588796d7214e189a6fef024bad4f29e7a155c93182a8b6f579b2c1fb2"**

So far so good. Last part is publickey, if understand correctly:**02f342968588796d7214e189a6fef024bad4f29e7a155c93182a8b6f579b2c1fb2**, which can be translated to address

Then I do following in python to get senders address:
import hashlib

```
pkey="02f342968588796d7214e189a6fef024bad4f29e7a155c93182a8b6f579b2c1fb2"

ripemd160 = hashlib.new('ripemd160')

ripemd160.update(hashlib.sha256(pkey.decode('hex')).digest())

```

but ripemd160.hexdigest() returns 8cdd1b71d32e53a9fe326212281a4a99a1c093a8, and thats not what i want.

It should return valid address, and result seems a bit off to me. I think .hexdigest is wrong way to do it, should be converted to base58.

How properly convert ripemd160.digest into account address?

Thanks a lot

**Tags:** address, development, base58


---

## 2 answers

### Answer by username_0 on 2014-04-23. Score: 0 | Accepted answer

I think I found solution to problem.. if someone will find it helpful, to get senders address for python:

```
import json
import bitcoinrpc
conn = bitcoinrpc.connect_to_remote('username', 'password', host='127.0.0.1', port=9332)
accounts=conn.listaccounts()
for a in accounts:
        name=json.dumps(a)
        name = name[1:-1]

        #print name
        tran=conn.listtransactions(name)
        for t in tran:
            act=t
            txid=t.txid
            raw=conn.getrawtransaction(txid,0)
            dec=conn.decoderawtransaction(raw)
            vin=dec['vin'][0]['txid']
            raw=conn.getrawtransaction(vin,0)
            dec=conn.decoderawtransaction(raw)
            vout=dec['vout']
            print json.dumps(vout[0]['scriptPubKey']['addresses'])[2:-2]

```

also, in config add **txindex=1** and run **litecoind -reindex** from cmdline

> **Comments:**
> **username_0**: props for C# snippet, inspirational.  

---

### Answer by username_1 on 2014-04-23. Score: 0

Sorry, i guess i misunderstood your question:
You have to encode the ripemd160 to base58 as you can see [here](http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html)

```
def pubKeyToAddr(s):
  ripemd160 = hashlib.new('ripemd160')
  ripemd160.update(hashlib.sha256(s.decode('hex')).digest())
  return utils.base58CheckEncode(0, ripemd160.digest())

```

Anyway, you can always check [the details](https://en.bitcoin.it/wiki/Technical_background_of_Bitcoin_addresses) of how to construct address.  
Aditionaly, if you want to use the [testnet](https://en.bitcoin.it/wiki/Testnet), remember to replace the first char from 0 to 0x6F like this

```
  return utils.base58CheckEncode(0x6F, ripemd160.digest())

```


---

