There aren't as many tools available in Python for managing multiple type of currencies in one wallet
Thankfully, I've found a command line tool, hd-wallet-derive that supports not only BIP32, BIP39, and BIP44, but
also supports non-standard derivation paths for the most popular wallets out there today!
hd-wallet-derive is "universal" wallet and can manage billions of addresses across 300+ coins.
For this exercise, I will only get 2 coins working: Ethereum and Bitcoin Testnet. Ethereum keys are the same format on any network, so the Ethereum keys should work with a custom networks or testnets.
-
PHP must be installed on your operating system (any version, 5 or 7).
-
Clone the
hd-wallet-derivetool. -
bitPython Bitcoin library. -
web3.pyPython Ethereum library.
This guide serves as a step by step process for setting up the hd-wallet-derive library used to derive BIP32 addresses and private keys for Bitcoin and other alternative coins or "altcoins."
Now that the latest version of PHP is installed on our machines, we can now proceed to the installation of the hd-wallet-derive library.
Execute the following steps:
-
Navigate to the Github website for the
hd-wallet-derivelibrary and scroll down to the installation instructions. -
Next, open a terminal and execute the following commands. If you are using Windows, you will need to open the
git-bashGUI viaC:\Program Files\Git\bin\bash.exedirectly to enable something calledttymode that makes the terminal more compatible with Unix systems. Once installed, you may move back to using the usualgit-bashterminal.
git clone https://github.com/dan-da/hd-wallet-derive
cd hd-wallet-derive
php -r "readfile('https://getcomposer.org/installer');" | php
php -d pcre.jit=0 composer.phar install- You should now have a folder called
hd-wallet-derivecontaining the PHP library.
- Using a command line navigate to your
hd-wallet-derivefolder.
- Run the following commands.
./hd-wallet-derive.php -g --key=xprv9tyUQV64JT5qs3RSTJkXCWKMyUgoQp7F3hA1xzG6ZGu6u6Q9VMNjGr67Lctvy5P8oyaYAL9CAWrUE9i6GoNMKUga5biW6Hx4tws2six3b9c./hd-wallet-derive.php -g --key=xprv9tyUQV64JT5qs3RSTJkXCWKMyUgoQp7F3hA1xzG6ZGu6u6Q9VMNjGr67Lctvy5P8oyaYAL9CAWrUE9i6GoNMKUga5biW6Hx4tws2six3b9c --numderive=3 --preset=bitcoincore --cols=path,address --path-changeWallet.py files runs all the functions which interact with hd-wallet-derive using the command line. The function below calls out the dictionary of coins with addresses and privkeys.
def derive_wallets(coin):
command = f'./derive -g --mnemonic="{mnemonic}" --cols=path,address,privkey,pubkey --format=json --coin="{coin}" --numderive= 2
p = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
output, err = p.communicate()
p_status = p.wait()
keys = json.loads(output)
return keys
coins = {
ETH: derive_wallets(ETH),
BTCTEST: derive_wallets(BTCTEST)
}
print(coins)To transfer money from one account to another you will need to run send_tx functions.
def send_tx(coin, account, to, amount):
tx = create_tx(coin, account, to, amount)
signed_tx = account.sign_transaction(tx)
if coin == ETH:
return w3.eth.sendRawTransaction(signed.rawTransaction)
elif coin == BTCTEST:
return NetworkAPI.broadcast_tx_testnet(signed_tx)In my case I ran this function in wallet.py file: send_tx(BTCTEST, Account_one, address_two, 0.002) to send BTCTEST from one account to another (see folder screen_shots for more imagies).


