libcrypto Examples¶
This directory contains practical examples for using libcrypto in real wallet, address generation, key conversion, public key, HD wallet, and batch generation workflows.
Each example is designed to be simple enough to run directly, while still demonstrating a real use case that can be adapted for production tools, offline utilities, wallet infrastructure, and blockchain automation systems.
Example Index¶
| Example | Description | Source | Details |
|---|---|---|---|
01_basic_multichain_addresses.py |
Generate Bitcoin, Ethereum, TRON, Litecoin, Dogecoin, and Bitcoin Cash addresses from one private key. | Source | Details |
02_all_supported_addresses.py |
Display all configured address formats for supported networks. | Source | Details |
03_generate_secure_wallet.py |
Generate a secure wallet and export private key, WIF, public keys, and major addresses. | Source | Details |
04_wif_import_export.py |
Export private keys to WIF and import WIF back into a wallet. | Source | Details |
05_public_key_only_addresses.py |
Generate addresses directly from compressed and uncompressed public keys. | Source | Details |
06_hd_wallet_from_mnemonic.py |
Generate a mnemonic and derive Bitcoin, Ethereum, and TRON wallets from HD paths. | Source | Details |
07_batch_wallet_generator_csv.py |
Generate multiple wallets and export keys and addresses to a CSV file. | Source | Details |
08_deterministic_test_vector.py |
Verify deterministic address generation against known secp256k1 test vectors. | Source | Details |
09_ecdsa_signing.py |
Deterministic ECDSA signing, verification, and public-key recovery (RFC 6979). | Source | Details |
10_message_signing.py |
Ethereum (EIP-191) and Bitcoin message signing, verification, and signer recovery. | Source | Details |
11_address_validation.py |
Validate and decode addresses with checksum verification across formats. | Source | Details |
12_watch_only_xpub.py |
Watch-only wallets using BIP32 public (CKDpub) derivation from an xpub. | Source | Details |
13_extended_coins.py |
Generate addresses for the extended coin set (Bitcoin Gold, Ravencoin, Qtum, Monacoin, Vertcoin, Zcash, and many EVM chains). | Source | Details |
| --- |
Requirements¶
Install the package before running the examples:
Or run the examples from the project root during local development:
All examples are written in Python and use the public libcrypto API.
01_basic_multichain_addresses.py¶
This example demonstrates how to derive multiple blockchain addresses from a single secp256k1 private key.
It is the best starting point for understanding how libcrypto maps one private key into different address formats across multiple networks.
What it demonstrates¶
- Bitcoin P2PKH address generation
- Bitcoin P2SH-P2WPKH nested SegWit address generation
- Bitcoin P2WPKH native SegWit address generation
- Bitcoin Taproot / P2TR address generation
- Ethereum address generation
- TRON Base58 address generation
- TRON hex address generation
- Litecoin address generation
- Dogecoin address generation
- Bitcoin Cash address generation
Run¶
Recommended use case¶
Use this example when you want to quickly verify multi-chain address generation from a known private key.
02_all_supported_addresses.py¶
This example prints all available address formats for supported networks.
It is useful for inspecting the complete address generation capability of the library and checking which formats are available for each supported coin.
What it demonstrates¶
- Generating all configured address types for a coin
- Iterating over multiple supported networks
- Inspecting address output in a structured way
- Verifying coin configuration behavior
Run¶
Recommended use case¶
Use this example when testing coin support, checking address format coverage, or validating newly added network configurations.
03_generate_secure_wallet.py¶
This example generates a new secure random wallet and prints private key, WIF, public keys, and major blockchain addresses.
What it demonstrates¶
- Secure random private key generation
- WIF export
- Compressed public key export
- Uncompressed public key export
- Bitcoin address generation
- Ethereum address generation
- TRON address generation
Run¶
Security note¶
This example prints sensitive wallet material.
Do not run it in shared terminals, public CI logs, cloud notebooks, remote shells, or production logging environments unless you fully control the execution context.
Recommended use case¶
Use this example when building local wallet generation tools, offline generators, or testing wallet creation workflows.
04_wif_import_export.py¶
This example demonstrates how to export a private key to WIF and import it back into a wallet.
What it demonstrates¶
- Private key generation
- Compressed WIF export
- Uncompressed WIF export
- WIF import
- Wallet reconstruction from WIF
- Address generation after WIF import
Run¶
Recommended use case¶
Use this example when working with Bitcoin-style wallet import/export flows or testing compatibility with WIF-based wallet systems.
05_public_key_only_addresses.py¶
This example demonstrates address generation directly from compressed and uncompressed public keys.
It is useful when private keys are not available, should not be exposed, or are handled by a separate secure system.
What it demonstrates¶
- Creating public keys from private keys
- Loading compressed public keys
- Loading uncompressed public keys
- Generating Bitcoin addresses from compressed public keys
- Generating Ethereum addresses from uncompressed public keys
- Generating TRON addresses from uncompressed public keys
Run¶
Recommended use case¶
Use this example when integrating with systems where public keys are available but private keys must remain isolated, such as signing services, HSM-backed flows, offline key stores, or watch-only tools.
06_hd_wallet_from_mnemonic.py¶
This example demonstrates mnemonic-based HD wallet derivation.
It shows how to generate a mnemonic, validate it, create an HD wallet, derive standard paths, and create normal Wallet objects from derived private keys.
What it demonstrates¶
- BIP39-style mnemonic generation
- Mnemonic validation
- HD wallet creation from mnemonic
- Path-based key derivation
- Bitcoin derivation
- Ethereum derivation
- TRON derivation
Example derivation paths¶
m/44'/0'/0'/0/0 Bitcoin BIP44
m/84'/0'/0'/0/0 Bitcoin native SegWit
m/44'/60'/0'/0/0 Ethereum
m/44'/195'/0'/0/0 TRON
Run¶
Security note¶
Mnemonic phrases are highly sensitive. Anyone with access to the mnemonic can derive the wallet keys.
Never store real mnemonic phrases in source code, logs, screenshots, tickets, chat messages, or public documentation.
Recommended use case¶
Use this example when building deterministic wallet tools, account derivation utilities, offline wallet generators, or wallet recovery systems.
07_batch_wallet_generator_csv.py¶
This example generates multiple wallets and exports the results to a CSV file using only Python standard library functionality.
What it demonstrates¶
- Batch wallet generation
- CSV export
- Private key export
- WIF export
- Bitcoin address generation
- Ethereum address generation
- TRON address generation
Run¶
Output¶
Security note¶
The generated CSV file contains private keys.
Do not commit it to a repository. Do not upload it to cloud storage without encryption. Do not share it with third parties. Do not use generated demo wallets for real funds unless your storage and operational security are properly designed.
Recommended use case¶
Use this example when creating local testing datasets, wallet infrastructure test fixtures, or offline batch generation tools.
08_deterministic_test_vector.py¶
This example verifies deterministic address generation against known secp256k1 address vectors.
It uses private key 1 and checks the expected outputs for Bitcoin, Ethereum, and TRON.
What it demonstrates¶
- Deterministic private key to address conversion
- Known test vector verification
- Bitcoin P2PKH verification
- Bitcoin P2SH-P2WPKH verification
- Bitcoin P2WPKH verification
- Bitcoin Taproot / P2TR verification
- Ethereum EIP-55 address verification
- TRON Base58 address verification
- TRON hex address verification
Run¶
Expected result¶
Recommended use case¶
Use this example after installation, after packaging, after CI changes, or after modifying cryptographic primitives such as secp256k1, Keccak-256, RIPEMD-160, Base58Check, Bech32, or Bech32m.
09_ecdsa_signing.py¶
This example signs a hash with a deterministic RFC 6979 nonce, verifies the signature, and recovers the signer's public key.
The signature is checked against the published RFC 6979 / secp256k1 test vector.
What it demonstrates¶
- Deterministic ECDSA signing (RFC 6979)
- Canonical low-S signatures
- Signature verification
- Public-key recovery
- DER serialization
Run¶
Expected result¶
10_message_signing.py¶
This example signs a message with both the Ethereum (EIP-191 personal_sign) and Bitcoin signed-message schemes, then recovers and verifies the signer address for each.
What it demonstrates¶
- Ethereum EIP-191 message signing and address recovery
- Bitcoin signed-message signing and address recovery
- Signature verification and rejection of tampered messages
Run¶
Expected result¶
11_address_validation.py¶
This example validates and decodes addresses across Base58Check, Bech32/Bech32m, and Ethereum EIP-55 formats, and confirms that tampered addresses are rejected.
What it demonstrates¶
- Base58Check checksum validation
- Bech32 and Bech32m validation
- Ethereum EIP-55 checksum validation and normalization
- Rejection of addresses with invalid checksums
- Structured decoding with
get_address_info
Run¶
Expected result¶
12_watch_only_xpub.py¶
This example exports an account-level xpub, imports it as a watch-only node, and derives receive addresses through BIP32 public (CKDpub) derivation without any private key.
What it demonstrates¶
- Exporting an account xpub with
neuter() - Importing an xpub with
HDNode.deserialize - Public (CKDpub) child derivation
- Matching public derivation against private derivation
Run¶
Expected result¶
13_extended_coins.py¶
This example generates addresses for the extended coin set: the additional Bitcoin-style networks (Bitcoin Gold, Ravencoin, Qtum, Monacoin, Vertcoin, and Zcash transparent) and many additional EVM-compatible chains, all from one private key.
What it demonstrates¶
- Bitcoin Gold, Ravencoin, Qtum, Monacoin, and Vertcoin address generation
- Zcash transparent (two-byte prefix) address generation
- SegWit formats for the SegWit-capable extended networks
- Identical EIP-55 addresses across all EVM-compatible chains
- Verification against known deterministic vectors
Run¶
Expected result¶
See Supported Coins & Networks for the full list of networks and their version bytes.
Recommended Learning Order¶
For new users, run the examples in this order:
- 01_basic_multichain_addresses.py
- 03_generate_secure_wallet.py
- 04_wif_import_export.py
- 05_public_key_only_addresses.py
- 06_hd_wallet_from_mnemonic.py
- 07_batch_wallet_generator_csv.py
- 08_deterministic_test_vector.py
This order starts with simple address generation, then moves into wallet creation, key import/export, public key workflows, HD wallet derivation, batch generation, and final deterministic verification.
Run All Examples¶
From the project root:
python examples/01_basic_multichain_addresses.py
python examples/02_all_supported_addresses.py
python examples/03_generate_secure_wallet.py
python examples/04_wif_import_export.py
python examples/05_public_key_only_addresses.py
python examples/06_hd_wallet_from_mnemonic.py
python examples/07_batch_wallet_generator_csv.py
python examples/08_deterministic_test_vector.py
On Windows PowerShell:
python .\examples\01_basic_multichain_addresses.py
python .\examples\02_all_supported_addresses.py
python .\examples\03_generate_secure_wallet.py
python .\examples\04_wif_import_export.py
python .\examples\05_public_key_only_addresses.py
python .\examples\06_hd_wallet_from_mnemonic.py
python .\examples\07_batch_wallet_generator_csv.py
python .\examples\08_deterministic_test_vector.py
Safety Guidelines¶
Some examples print or export sensitive wallet material.
Before running the examples, understand the following rules:
- Never use demo private keys for real funds.
- Never commit generated private keys.
- Never commit generated mnemonic phrases.
- Never commit generated WIF strings.
- Never commit generated CSV files containing private keys.
- Never run private-key examples inside public CI logs.
- Never paste real wallet material into issue trackers, chat systems, or documentation.
- Prefer offline execution for sensitive wallet generation workflows.
These examples are intended for development, testing, education, and controlled local workflows.