Search code examples
pythonblockchainbitcoin

how to create the address of litecoin using pycoin library?


I have generate the address of bitcoin using python script. How to generate the address of Litecoin.

Here is my code to generate bitcoin address

import hashlib
from pycoin import ecdsa, encoding
import os
import codecs
for i in range(10):
    rand = codecs.encode(os.urandom(32), 'hex').decode()
    secret_exponent= int('0x'+rand, 0)
    print ('WIF: ' + encoding.secret_exponent_to_wif(secret_exponent, compressed=False))
    public_pair = ecdsa.public_pair_for_secret_exponent(ecdsa.secp256k1.generator_secp256k1, secret_exponent)
    hash160 = encoding.public_pair_to_hash160_sec(public_pair, compressed=True)
    print('Bitcoin address: %s' % encoding.hash160_sec_to_bitcoin_address(hash160))

Solution

  • Here in this function secret_exponent_to_wif

    def secret_exponent_to_wif(se, compressed):
        blob = to_bytes_32(se)
        if compressed:
            blob += b'\01'
        return BitcoinMainnet.ui.wif_for_blob(blob)
    

    Here it uses BitcoinMainnet to generate Bitcoin address.You just use LitecoinMannet to generate Litecoin address . It is already there in pycoin.coins.litecoin library. By changing the corresponding network values you can generate address of any crypto key