Multi-Blockchain Wallet in Python: Build a Universal Crypto Wallet

·

Creating a multi-blockchain wallet in Python opens the door to managing hundreds of cryptocurrencies and generating billions of addresses—all from a single, programmable interface. This guide walks you through building a universal crypto wallet capable of supporting multiple blockchains, with working examples for Bitcoin Testnet (BTCTEST) and Ethereum (ETH). Whether you're a developer exploring blockchain interoperability or a crypto enthusiast looking to understand wallet architecture, this tutorial delivers hands-on implementation steps, practical insights, and troubleshooting tips.

By the end, you’ll have a functional Python-based wallet that can generate keys, derive addresses across chains, and send transactions on testnets—laying the foundation for a full-scale multi-asset digital wallet system.

👉 Discover how to manage multiple blockchain assets securely with advanced tools


Why Build a Multi-Blockchain Wallet?

A universal cryptocurrency wallet eliminates the need for separate applications for each blockchain. Instead of juggling different wallets for Bitcoin, Ethereum, Litecoin, or newer altcoins, a unified solution streamlines key management, transaction signing, and address generation.

This project leverages hierarchical deterministic (HD) wallet principles and open-source libraries to support multiple blockchains through a single codebase. The result? One script that can scale across networks while maintaining security and usability.

Core Keywords:

These keywords reflect high-intent search queries from developers and tech-savvy users interested in blockchain development, wallet architecture, and cross-chain interoperability.


Required Dependencies and Setup

Before diving into coding, ensure your environment is properly configured. The following tools and libraries are essential:

Step-by-Step Installation

  1. Create Your Project Directory

    mkdir wallet && cd wallet
  2. Clone hd-wallet-derive Tool

    git clone https://github.com/dan-da/hd-wallet-derive.git
    cd hd-wallet-derive && composer install
  3. Create a Symlink for Easy Access
    From the main wallet directory:

    ln -s hd-wallet-derive/hd-wallet-derive.php derive
  4. Verify Installation
    Run a test command:

    php derive --key="your-xprv-or-mnemonic" --cols=path,address --numaddr=2

    If output appears with derived addresses, you're ready to proceed.

  5. Install Python Libraries

    pip install bit web3

With dependencies installed, you now have the foundation to build your universal wallet logic in Python.

👉 Explore secure ways to handle private keys and blockchain interactions


Building the Universal Wallet Script

Create a file named wallet.py in your project root. This will serve as the core of your multi-blockchain wallet.

Start by defining constants and importing required modules:

from bit import Key, network
from bit.network import NetworkAPI
from web3 import Web3
from web3.middleware import geth_poa_middleware
import subprocess
import json

# Blockchain constants
BTCTEST = 'btctest'
ETH = 'eth'

# Derive addresses using hd-wallet-derive via subprocess
def derive_wallets(mnemonic, coin, num_addresses=3):
    command = f"php derive --mnemonic='{mnemonic}' --coin={coin} --numaddr={num_addresses} --format=json"
    result = subprocess.check_output(command, shell=True)
    return json.loads(result)

Next, define functions to convert private keys into usable account objects:

def priv_key_to_account(coin, priv_key):
    if coin == BTCTEST:
        return Key(priv_key)
    elif coin == ETH:
        return w3.eth.account.from_key(priv_key)

Then implement transaction logic:

def send_tx(coin, account, recipient, amount):
    if coin == BTCTEST:
        tx_hash = account.send([(recipient, amount, 'btc')])
        return tx_hash
    elif coin == ETH:
        w3.eth.send_transaction({
            'from': account.address,
            'to': recipient,
            'value': w3.toWei(amount, 'ether'),
            'gas': 21000,
            'gasPrice': w3.eth.gas_price,
            'nonce': w3.eth.get_transaction_count(account.address),
        })

This modular structure allows seamless integration across different blockchains by abstracting network-specific logic.


Funding and Testing Transactions on Bitcoin Testnet

To test your wallet functionality:

  1. Generate a Bitcoin Testnet address using your mnemonic:

    btc_test_addresses = derive_wallets("your mnemonic here", BTCTEST)
  2. Use a Bitcoin Testnet faucet to fund your address. Search “Bitcoin Testnet faucet” to find active services.
  3. In a Python shell:

    from wallet import *
    
    sender_account = priv_key_to_account(BTCTEST, coins["btc-test"][0]['privkey'])
    recipient = coins["btc-test"][1]["address"]
    send_tx(BTCTEST, sender_account, recipient, 0.0001)
  4. Track the transaction using a block explorer like tbtc.bitaps.com (note: original link removed per guidelines).

You should see the transaction move from pending to confirmed.


Working with Local Ethereum PoA (Proof-of-Authority) Network

For Ethereum testing, especially on private or local Proof-of-Authority (PoA) networks:

  1. Add your generated ETH address (without the 0x prefix) to the alloc section of your genesis.json.
  2. Reinitialize each node:

    geth --datadir node1 init genesis.json
  3. Inject PoA middleware in wallet.py:

    w3 = Web3(Web3.HTTPProvider("http://localhost:8545"))
    w3.middleware_onion.inject(geth_poa_middleware, layer=0)
  4. Due to a known issue in web3.py, gas price estimation fails on empty chains. Workaround: Send an initial transaction manually using MyCrypto or MetaMask.
  5. Once funded, use your script:

    eth_account = priv_key_to_account(ETH, eth_private_key)
    send_tx(ETH, eth_account, "0xRecipientAddress", 2)

If transactions remain "Pending," check:

👉 Learn how professional platforms handle Ethereum transactions efficiently


Frequently Asked Questions (FAQ)

Q: Can this wallet support more than Bitcoin and Ethereum?
A: Yes! By updating the coin codes in hd-wallet-derive (e.g., LTC, DOGE, BSC), you can extend support to over 100+ blockchains.

Q: Is it safe to use this wallet for mainnet assets?
A: Only if enhanced with secure key storage (e.g., hardware modules or encrypted vaults). For learning and testnets, it's ideal.

Q: Why do I need PHP for a Python project?
A: The hd-wallet-derive tool is written in PHP and offers unmatched multi-coin derivation capabilities. It's called via subprocess from Python.

Q: What causes Ethereum transactions to stay “Pending”?
A: Common causes include low gas prices, incorrect nonce values, or missing PoA middleware injection on private networks.

Q: How scalable is this design?
A: Highly scalable. With proper indexing and database integration, one mnemonic can generate billions of addresses across chains.

Q: Can I automate faucet requests?
A: Some faucets allow API access; others require CAPTCHA solving. Automate cautiously to avoid rate-limiting.


With this foundation, you're equipped to expand into mainnet integrations, UI development, or even mobile wallet backends. The future of crypto lies in interoperability—and this project puts you on the front lines.