Skip to main content

Simple BIP32 (HD) wallet creation for BTC, BCH, LTC, DASH, USDT (Omni) and DOGE

Project description

ZPyWallet

Python version PyPi version PyPi status Code coverage

Simple BIP32 (HD) wallet creation for: BTC, BCH, ETH, LTC, DASH, USDT (Omni), DOGE

BIP32 (or HD for “hierarchical deterministic”) wallets allow you to create child wallets which can only generate public keys and don’t expose a private key to an insecure server.

This library simplifies the process of creating new wallets for the BTC, BCH, ETH, LTC, DASH, USDT (Omni) and DOGE cryptocurrencies. In addition, it can also create Bitcoin Bech32 addresses for all supported witness versions.

This is a fork of PyWallet <https://github.com/ranaroussi/pywallet> with support for more coins, and some bugfixes.

Enjoy!


Installation

Install via PiP:

$ sudo pip install zpywallet

Example code:

Create HD Wallet

The following code creates a new Bitcoin HD wallet:

# create_btc_wallet.py

from zpywallet import wallet

# generate 12 word mnemonic seed
seed = wallet.generate_mnemonic()

# create bitcoin wallet
w = wallet.create_wallet(network="BTC", seed=seed, children=1)

print(w)

Output looks like this:

$ python create_btc_wallet.py

{
  "coin": "BTC",
  "seed": "guess tiny intact poet process segment pelican bright assume avocado view lazy",
  "address": "1HwPm2tcdakwkTTWU286crWQqTnbEkD7av",
  "xprivate_key": "xprv9s21ZrQH143K2Dizn667UCo9oYPdTPSMWq7D5t929aXf1kfnmW79CryavzBxqbWfrYzw8jbyTKvsiuFNwr1JL2qfrUy2Kbwq4WbBPfxYGbg",
  "xpublic_key": "xpub661MyMwAqRbcEhoTt7d7qLjtMaE7rrACt42otGYdhv4dtYzwK3RPkfJ4nEjpFQDdT8JjT3VwQ3ZKjJaeuEdpWmyw16sY9SsoY68PoXaJvfU",
  "wif": "L1EnVJviG6jR2oovFbfxZoMp1JknTACKLzsTKqDNUwATCWpY1Fp4",
  "children": [{
     "address": "1E3btRwsoJx2jUcMnATyx7poHhV2tomL8g",
     "path": "m/0",
     "xpublic_key": "xpub69Fho5TtAbdoXyWzgUV1ZYst9K4bVfoGNLZxQ9u5js4Rb1jEyUjDtoATXbWvAcV8cERCMMnH8wYRVVUsRDSfaMjLqaY3TvD7Am9ALjq5PsG",
     "wif": "KysRDiwJNkS9VPzy1UH76DrCDizsWKtEooSzikich792RVzcUaJP"
 }]
}

Similarly, you can do the same for an Ethereum wallet:

# create_eth_wallet.py

from zpywallet import wallet

seed = wallet.generate_mnemonic()
w = wallet.create_wallet(network="ETH", seed=seed, children=1)

print(w)

Output looks like this (no WIF for Ethereum):

$ python create_eth_wallet.py

{
  "coin": "ETH",
  "seed": "traffic happy world clog clump cattle great toy game absurd alarm auction",
  "address": "0x3b777f60eb04fcb13e6b27e468532e491409722e",
  "xprivate_key": "xprv9yTuSjwb95QZznV6epMWpb4Kpc2S8ZRaQuAf5B697YXtQD2tDmmJ5KvwJWVjtbVrdJ1WBKNnuodrpTKGfHfiPSEgrAxUjL5RP1gQwwT3fFx",
  "xpublic_key": "xpub6GhhMtkVjoPi5DKtqapKzMzrzdGjo1EPc7Ka6KdeoXYdCrTBH1Hu1wKysm8boWSy8VeTKVJi6gQJ2qJ4YG2ZhvFDcUUgMJrFCJWN1PGtBry",
  "wif": "",
  "children": [{
    "address": "0x87eb82d43fa7316df0a989c0d951a9037ed02f9b",
    "path": "m/0",
    "xpublic_key": "xpub6LnpVXD73jNuAYXxzQCnEY6wXQspwkiAEkZWoX4BW9Tzx6KbUrMUYAU1Yvw4kebPHSPiEJPo8irHWHSwQR6WuVwUj85xURsugPWeJVH6sau",
    "wif": ""
  }]
}

* Valid options for network are: BTC, BTG, BCH, LTC, DASH, DOGE

Create Child Wallet

You can create child-wallets (BIP32 wallets) from the HD wallet’s Extended Public Key to generate new public addresses without revealing your private key.

Example:

# create_child_wallet.py

from zpywallet import wallet

WALLET_PUBKEY = 'YOUR WALLET XPUB'

# generate address for specific user (id = 10)
user_addr = wallet.create_address(network="BTC", xpub=WALLET_PUBKEY, child=10)

# or generate a random address, based on timestamp
rand_addr = wallet.create_address(network="BTC", xpub=WALLET_PUBKEY)

print("User Address\n", user_addr)
print("Random Address\n", rand_addr)

Output looks like this:

$ python create_child_wallet.py

User Address
{
  "address": "13myudz3WhpBezoZue6cwRUoHrzWs4vCrb",
  "path": "m/0/395371597"
}
Random Address
{
  "address": "1KpS2wC5J8bDsGShXDHD7qdGvnic1h27Db",
  "path": "m/0/394997119"
}

CONTRIBUTING

Bugfixes and enhancements are welcome. Please read CONTRIBUTING.md for contributing instructions.

At the moment, I’m not accepting pull requests for new coins unless they are big and historic coins such as Tether (ERC20), BNB and XMR.

IMPORTANT

I highly recommend that you familiarize yourself with the Blockchain technology and be aware of security issues. Reading Mastering Bitcoin and going over Steven Buss’s security notes on the Bitmerchant repository is a good start.

Enjoy!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zpywallet-0.4.0.tar.gz (53.3 kB view hashes)

Uploaded Source

Built Distribution

zpywallet-0.4.0-py2.py3-none-any.whl (41.4 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page