DEV Community

Cover image for How to Generate Any Wallet with Cryptofuzz
Mmdrza
Mmdrza

Posted on

How to Generate Any Wallet with Cryptofuzz

What is Cryptofuzz?

This library is for faster and easier use in the field of cryptography and tools for creating various private keys and mnemonics and converting them into other components required for a cryptocurrency wallet for Bitcoin, Ethereum, Dash, Dogecoin, Litecoin, TON, Tron, Bitcoin Gold and ... several other different currencies.

In the following, I will show you how you can implement and execute the best and most optimized code in Python using this library of private and public keys and mnemonics to convert them into addresses and other security keys for a wallet using the least amount of code.

Install

PIP

install with pip in your terminal

pip install --upgrade cryptofuzz
Enter fullscreen mode Exit fullscreen mode

GIT

install with git in your terminal

git clone https://github.com/Pymmdrza/cryptoFuzz
cd cryptoFuzz
python3 setup.py install
Enter fullscreen mode Exit fullscreen mode

Use

Private Key

Private Key To Bitcoin Wallet

convert private key hex to all address format bitcoin
Generating Bitcoin Addresses with Cryptofuzz

This example demonstrates generating various types of Bitcoin addresses using the cryptofuzz library in Python, utilizing a specific private key. The process results in addresses that support different transaction protocols and optimizations.
Implementing Address Generation

The script below initializes a Bitcoin object and generates four types of addresses: P2PKH, P2SH, P2WPKH, and P2WSH, based on the provided private key.

from cryptofuzz import Bitcoin

btc = Bitcoin()

# private key 
privatekey = "0A97965...A45517"

# Generate P2PKH address
p2pkh = btc.hex_addr(privatekey, 'p2pkh')

# Generate P2SH address
p2sh = btc.hex_addr(privatekey, 'p2sh')

# Generate P2WPKH address
p2wpkh = btc.hex_addr(privatekey, 'p2wpkh')

# Generate P2WSH address
p2wsh = btc.hex_addr(privatekey, 'p2wsh')

Enter fullscreen mode Exit fullscreen mode
type description example
p2pkh Pay to Public Key Hash 1M8Qk46ERsPrEtWLBRSET5NUH2Ck5wwREU
p2sh Pay to Script Hash 34omeRgNLiDqbP7BTdVUSGoPBoFKy3BX44
p2wpkh Pay to Witness Public Key Hash bc1qmnyn7x24xj6vraxeeq56dfkxa009tvhgqffstc
p2wsh Pay to Witness Script Hash bc1qgahjmt5vkm8wkv70adwyrvw9qy22cygafc7h9nur9nfk8gj6dc3s3v24wf

Private Key To Compressed and Uncompressed

use the hex_to_addr method from the Convertor class for compressed and uncompressed addresses:

from cryptofuzz import Convertor

conv = Convertor()

# private key 
privatekey = "0A97965...A45517"

# Compressed Bitcoin Address Wallet
compressed_addr = conv.hex_to_addr(privatekey, True)

# Uncompressed Bitcoin Address Wallet
uncompressed_addr = conv.hex_to_addr(privatekey, False)
Enter fullscreen mode Exit fullscreen mode

Private Key To Ethereum Wallet

convert private key hex to Ethereum address wallet

from cryptofuzz import Ethereum

ETH = Ethereum()

# private key
privatekey = "0A97965...A45517"

# Ethereum Address Wallet
ethereum_address = ETH.hex_addr(privatekey)
Enter fullscreen mode Exit fullscreen mode

Private Key To Dash Wallet

convert private key hex to Dash address wallet

from cryptofuzz import Dash

DASH = Dash()

# private key
privatekey = "0A97965...A45517"

# Dash Address Wallet
dash_address = DASH.hex_addr(privatekey)
Enter fullscreen mode Exit fullscreen mode

Private Key To Dogecoin Wallet

convert private key hex to Dogecoin address wallet

from cryptofuzz import Dogecoin

doge = Dogecoin()

# private key
privatekey = "0A97965...A45517"

# Dogecoin Address Wallet
dogecoin_address = doge.hex_addr(privatekey)
Enter fullscreen mode Exit fullscreen mode

Private Key To Litecoin Wallet

convert private key hex to Litecoin address wallet

from cryptofuzz import Litecoin

LTC = Litecoin()

# private key
privatekey = "0A97965...A45517"

# Litecoin Address Wallet
litecoin_address = LTC.hex_addr(privatekey)
Enter fullscreen mode Exit fullscreen mode

Private Key To Tron Wallet

convert private key hex to Tron address wallet

from cryptofuzz import Tron

TRX = Tron()

# private key
privatekey = "0A97965...A45517"

# Tron Address Wallet
tron_address = TRX.hex_addr(privatekey)
Enter fullscreen mode Exit fullscreen mode

Private Key To Bitcoin Gold Wallet

convert private key hex to Bitcoin Gold address wallet

from cryptofuzz import BitcoinGold

BTG = BitcoinGold()

# private key
privatekey = "0A97965...A45517"

# Bitcoin Gold Address Wallet
bitcoin_gold_address = BTG.hex_addr(privatekey)
Enter fullscreen mode Exit fullscreen mode

Private Key To Zcash Wallet

convert private key hex to Zcash address wallet

from cryptofuzz import Zcash

ZEC = Zcash()

# private key
privatekey = "0A97965...A45517"

# Zcash Address Wallet
zcash_address = ZEC.hex_addr(privatekey)
Enter fullscreen mode Exit fullscreen mode

TON Wallet

basic chain (workchain 0)

from cryptofuzz import Ton
ton = Ton(mainnet=True, workchain=0)
Enter fullscreen mode Exit fullscreen mode

masterchain (workchain -1)

from cryptofuzz import Ton
ton = Ton(mainnet=True, workchain=-1)
Enter fullscreen mode Exit fullscreen mode

from cryptofuzz import Ton
ton = Ton(mainnet=True, workchain=-1)
# or
ton = Ton(mainnet=True, workchain=0) # default
Enter fullscreen mode Exit fullscreen mode

testnet supported mainnet=False

Private Key To TON Address Wallet

convert private key hex to TON address wallet from privatekey_to_address function in Ton class

from cryptofuzz import Ton

TON = Ton()

# private key
privatekey = "0A97965...A45517"

# TON Address Wallet bounceable
bounceable_address = TON.privatekey_to_address(privatekey)
# TON Address Wallet non-bounceable
unbounceable_address = TON.privatekey_to_address(privatekey, False)
Enter fullscreen mode Exit fullscreen mode
  • Parameters privatekey_to_address: in_privatekey: str, bounceable: bool (default: True)
  • Returns: str address in Base64 format (urlsafe_b64encode)
  • Example: baddr = ton.privatekey_to_address('0abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', True)
  • Example: uaddr = ton.privatekey_to_address('0abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', False)

Mnemonic To TON Address Wallet

Convert Mnemonic to User-Friendly TON Address (bounceable, Un-Bounceable)

from cryptofuzz import Ton
ton = Ton(mainnet=True)
# Create mnemonic (Only : *24 words)
mnemonic = ('abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon '
            'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about')
# Convert mnemonic to Bounceable TON address
baddr = ton.mnemonic_to_address(mnemonic, True)
# Convert mnemonic to Unbounceable TON address
uaddr = ton.mnemonic_to_address(mnemonic, False)
Enter fullscreen mode Exit fullscreen mode
  • Parameters mnemonic_to_address: mnemonic: str, bounceable: bool (default: True)
  • Returns: str address in Base64 format (urlsafe_b64encode)
  • Example: baddr = ton.mnemonic_to_address('abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about', True)
  • Example: uaddr = ton.mnemonic_to_address('abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about', False)

Decimal To TON Address Wallet

Convert Decimal to User-Friendly TON Address (bounceable, Un-Bounceable)

from cryptofuzz import Ton
ton = Ton(mainnet=True)
# Convert decimal to Bounceable TON address
baddr = ton.decimal_to_address(1, True)
# Convert decimal to Unbounceable TON address
uaddr = ton.decimal_to_address(1, False)
Enter fullscreen mode Exit fullscreen mode
  • Parameters decimal_to_address: decimal: int, bounceable: bool (default: True)
  • Returns: str address in Base64 format (urlsafe_b64encode)
  • Example: baddr = ton.decimal_to_address(1, True)
  • Example: uaddr = ton.decimal_to_address(1, False)
  • Note: Decimal Value must be less than 2^256 - 1

TON Address To Raw Address

Convert User-Friendly TON Address To Raw Address

from cryptofuzz import Ton
ton = Ton(mainnet=True)
addr = 'EQDlW5BbpUj6J0ApOxTlZ_CHYYR9NlPc3ahYQ8HtVlbQc6AA'
baddr = ton.raw_address(addr)
# output: 0:E55B905BA548FA2740293B14E567F08761847D3653DCDDA85843C1ED5656D073
Enter fullscreen mode Exit fullscreen mode
  • Parameters raw_address: address: str
  • Returns: str raw address
  • Example: baddr = ton.raw_address('EQDlW5BbpUj6J0ApOxTlZ_CHYYR9NlPc3ahYQ8HtVlbQc6AA')
  • Note: Address Value must be in Base64 format (urlsafe_b64encode)

Mnemonic

Generate Mnemonic

Generate Mnemonic (Only : 12 , 24 words)

from cryptofuzz import Generator

gen = Generator()

# 12 words
mnemonic_12 = gen.generate_mnemonic(12)

# 24 words
mnemonic_24 = gen.generate_mnemonic(24)
Enter fullscreen mode Exit fullscreen mode
  • Parameters generate_mnemonic: length: int (_default: 12)
  • Returns: str mnemonic
  • Example: mnemonic_12 = gen.generate_mnemonic(12)
  • Example: mnemonic_24 = gen.generate_mnemonic(24)

Mnemonic To Private Key

Convert Mnemonic to Private Key

from cryptofuzz import Convertor

conv = Convertor()

# Mnemonic
mnemonic = ('abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon '
            'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about')

# Private Key
privatekey = conv.mne_to_hex(mnemonic)
Enter fullscreen mode Exit fullscreen mode
  • Parameters mne_to_hex: mnemonic: str
  • Returns: str private key
  • Example: privatekey = conv.mne_to_hex(mnemonic)

Mnemonic To Address

Convert Mnemonic to compressed address and uncompressed bitcoin address

from cryptofuzz import Convertor

conv = Convertor()

# Mnemonic
mnemonic = ('abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon '
            'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about')

# compressed address
compressed_address = conv.mne_to_addr(mnemonic)

# uncompressed address
uncompressed_address = conv.mne_to_addr(mnemonic, False)
Enter fullscreen mode Exit fullscreen mode
  • Parameters mne_to_addr: mnemonic: str, compressed: bool (default: True)
  • Returns: str address
    • compressed address: str compressed address
    • uncompressed address: str uncompressed address
    • Example: compressed_address = conv.mne_to_addr(mnemonic), uncompressed_address = conv.mne_to_addr(mnemonic, False)

Mnemonic To Seed

from  cryptofuzz import Mnemonic

mne = Mnemonic()

words = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"

seed = mne.to_seed(words)
Enter fullscreen mode Exit fullscreen mode
  • Parameters to_seed: mnemonic: str
  • Returns: bytes seed

Mnemonic To Root Private Key (Extended Private Key / XPRV)

from cryptofuzz import Convertor

conv = Convertor()

# Mnemonic
mne = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"

# Root Private Key
root_private_key = conv.mne_to_xprv(mne)
Enter fullscreen mode Exit fullscreen mode
  • Parameters mne_to_xprv: mnemonic: str
  • Returns: str root private key
  • Example: root_private_key = conv.mne_to_xprv(mne)
  • Note: Mnemonic must be 12 or 24 words

Mnemonic To Root Public Key (Extended Public Key / XPUB)

from cryptofuzz import Convertor

conv = Convertor()

# Mnemonic
mne = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"

# Root Public Key
root_public_key = conv.mne_to_xpub(mne)
Enter fullscreen mode Exit fullscreen mode
  • Parameters mne_to_xpub: mnemonic: str
  • Returns: str root public key
  • Example: root_public_key = conv.mne_to_xpub(mne)
  • Note: Mnemonic must be 12 or 24 words

Mnemonic To Wallet Import Format (WIF)

convert mnemonic words to wallet import format (WIF) compressed and uncompressed

from cryptofuzz import Convertor

conv = Convertor()

# Mnemonic
mne = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"

# WIF compressed
wif_compressed = conv.mne_to_wif(mne)

# WIF uncompressed
wif_uncompressed = conv.mne_to_wif(mne, False)
Enter fullscreen mode Exit fullscreen mode
  • Parameters mne_to_wif: mnemonic: str, compress: bool (default: True)
  • Returns: str WIF
  • Example: wif_compressed = conv.mne_to_wif(mne), wif_uncompressed = conv.mne_to_wif(mne, False)
  • Note: Mnemonic must be 12 or 24 words

WIF (Wallet Import Format)

WIF To Private Key

convert WIF to private key (hex)

from cryptofuzz import Convertor

conv = Convertor()

# WIF
wif = '5KQwrPbwdL6PhX7ayB3GEpWUPaK7aRm2MV8NHWl7ZT8g2VTXYG7J'

# Private Key
privatekey = conv.wif_to_hex(wif)
Enter fullscreen mode Exit fullscreen mode

WIF To Address

convert WIF to compressed and uncompressed address

from cryptofuzz import Convertor

conv = Convertor()

# WIF
wif = '5KQwrPbwdL6PhX7ayB3GEpWUPaK7aRm2MV8NHWl7ZT8g2VTXYG7J'

# compressed address
compressed_address = conv.wif_to_addr(wif)

# uncompressed address
uncompressed_address = conv.wif_to_addr(wif, False)
Enter fullscreen mode Exit fullscreen mode

Block

read block data from block file (bitcoin core sync data file's) [ blk00001.dat ]

from cryptofuzz import block
import os

# path block file
path_data = os.path.join("<BITCOIN CORE SYNC BLOCK PATH>")
block_path = os.path.join(path_data, "blk00001.dat")  # first block file sync
# full block data
block_data = block.reader(block_path) 
Enter fullscreen mode Exit fullscreen mode

Top comments (0)