<p>Note: <a href="https://en.bitcoin.it/wiki/Wallet_import_format" rel="nofollow noreferrer">WIF</a> is a format for private keys, not addresses.  There are multiple address formats, but the most common is P2PKH (<strong>hash</strong> of a <em>public</em> key).</p>

<p>I recommend looking that the code for Electrum to learn about how to work with public keys and addresses in Python, (check out <a href="https://github.com/spesmilo/electrum/blob/master/electrum/bitcoin.py" rel="nofollow noreferrer">bitcoin.py</a>).  It contains everything you need and is reliable code used by many thousands of users to secure their bitcoin.</p>

CC BY-SA 4.0
2020-04-12T11:07:33.683Z
TY  You're right.  I'm a beginner at this.
user104853
CC BY-SA 4.0
2020-04-05T22:50:42.833Z
2020-04-05T22:50:42.833Z
Jonathan Cross
<p>I have code which generates WIF keys from hex keys.  It just need a few more lines to generate WIF addresses.</p>

<h1>------------------------</h1>

<p><B><PRE>
import binascii, hashlib, base58, sys</p>

<p>def convert(z):</p>

<pre><code>private_key_static = z

extended_key = "80"+private_key_static+"01"

first_sha256 = hashlib.sha256(binascii.unhexlify(extended_key)).hexdigest()

second_sha256 = hashlib.sha256(binascii.unhexlify(first_sha256)).hexdigest()

final_key = extended_key+second_sha256[:8]

WIF = base58.b58encode(binascii.unhexlify(final_key)).decode ('ascii')

print (WIF)
</code></pre>

<p>with open("HEX.txt") as file:
    for line in file:
       convert(str.strip(line))</p>

<p></PRE></B></p>

<address><python><wallet-import-format>
I need a few lines of python to make WIF addresses
user104853
# I need a few lines of python to make WIF addresses

(Asked by: username_0 on 2020-04-05)

I have code which generates WIF keys from hex keys.  It just need a few more lines to generate WIF addresses.
------------------------

import binascii, hashlib, base58, sys
def convert(z):
private_key_static = z

extended_key = "80"+private_key_static+"01"

first_sha256 = hashlib.sha256(binascii.unhexlify(extended_key)).hexdigest()

second_sha256 = hashlib.sha256(binascii.unhexlify(first_sha256)).hexdigest()

final_key = extended_key+second_sha256[:8]

WIF = base58.b58encode(binascii.unhexlify(final_key)).decode ('ascii')

print (WIF)

with open("HEX.txt") as file:
    for line in file:
       convert(str.strip(line))

**Tags:** address, python, wallet-import-format


---

## 1 answers

### Answer by username_1 on 2020-04-05. Score: 1

Note: [WIF](https://en.bitcoin.it/wiki/Wallet_import_format) is a format for private keys, not addresses. There are multiple address formats, but the most common is P2PKH (**hash** of a *public* key).

I recommend looking that the code for Electrum to learn about how to work with public keys and addresses in Python, (check out [bitcoin.py](https://github.com/spesmilo/electrum/blob/master/electrum/bitcoin.py)). It contains everything you need and is reliable code used by many thousands of users to secure their bitcoin.

> **Comments:**
> **username_0**: TY  You're right.  I'm a beginner at this.  

---

