Skip to content

Create BitcoinCash from privatekey [bitcoincash:qr...] #57

Open

Description

@Pymmdrza

How create bitcoincash address (bitcoincash:qr...) from this package ???
used this source , not worked to this type address :

from hdwallwet import HDWallet
from hdwallet.symbols import BCH as SYMBOL
hdwallet: HDWallet = HDWallet(symbol=SYMBOL)
hdwallet.from_private_key(private_key=private_key)
addr = hdwallet.p2wpkh_address()
print(addr)
# out: bc1qgrdf2l6z6u78zpdj4excxp44r4amquxlalcnpd

i need this address type : bitcoincash:q....

Activity

  1. added
    enhancement
    address
    on Jun 3, 2022
  2. meherett commented on Jun 3, 2022

    @meherett
    Collaborator

    @Pymmdrza, Basically Bitcoin Cash has 3 different types of Pay to Public Key Hash (P2PKH) addresses. Those are:
    1, CashAddr addresses for Bitcoin Cash (ie starting with q or bitcoincash:q instead of 1)
    2, BitPay-style addresses for Bitcoin Cash (ie starting with C instead of 1)
    3, Legacy addresses for Bitcoin Cash (ie starting with 1)

    So, on the currerent version of this hdwallet package; you can only generate addresses on the second type of BitPay-style addresses for Bitcoin Cash (ie starting with C instead of 1) style. In the upcoming version I will add the rest of them.

    And also call this hdwallet.p2pkh_address() instead of hdwallet.p2wpkh_address() function because p2wpkh_address() is Pay to Witness Public Key Hash address or it's SegWit address.

    Thanks.

  3. pbies commented on Feb 4, 2026

    @pbies

    I have similar problem:
    I have BCH = Bitcoin Cash addresses dump, balanced addresses.
    I also have hex pvks converted to BCH WIFs and addresses.
    They don't match: I mean original addresses are 42 letters long, and when I remove "bitcoincash1" from the second - generated by HDwallet - I am getting 39 and 59 letters.

    Valid address from BCH dump:

    qpqgzrp8803q3hc2w48wx4avpgry040cmvqhy4kgk8

    Invalid addresses from HDwallet:

    bitcoincash1qq6hag67dl53wl99vzg42z8eyzfz2xlkvsyvj90 bitcoincash1q4qp0380kg75cqv25k4zruwa87wefwz0uefv78jekagm2j8568rwq8vluve

    (remove "bitcoincash1" from both and you get 39/59 letters)

    How to operate properly here?

  4. pbies commented on Feb 5, 2026

    @pbies

    @meherett addressing to you - maybe you know what is this about?

  5. Pymmdrza commented on Feb 5, 2026

    @Pymmdrza
    Author

    I have similar problem: I have BCH = Bitcoin Cash addresses dump, balanced addresses. I also have hex pvks converted to BCH WIFs and addresses. They don't match: I mean original addresses are 42 letters long, and when I remove "bitcoincash1" from the second - generated by HDwallet - I am getting 39 and 59 letters.

    Valid address from BCH dump:

    qpqgzrp8803q3hc2w48wx4avpgry040cmvqhy4kgk8

    Invalid addresses from HDwallet:

    bitcoincash1qq6hag67dl53wl99vzg42z8eyzfz2xlkvsyvj90 bitcoincash1q4qp0380kg75cqv25k4zruwa87wefwz0uefv78jekagm2j8568rwq8vluve

    (remove "bitcoincash1" from both and you get 39/59 letters)

    How to operate properly here?

    Tip

    It can be of great help to you if you examine it a little carefully:
    libcrypto / Address Class

  6. pbies commented on Feb 5, 2026

    @pbies

    @Pymmdrza I don't see answer to my question in that code. It is just the same code Base58 for encoding addresses. No BCH distinction I see there. What's on your mind?

  7. Pymmdrza commented on Feb 5, 2026

    @Pymmdrza
    Author

    @Pymmdrza I don't see answer to my question in that code. It is just the same code Base58 for encoding addresses. No BCH distinction I see there. What's on your mind?

    🫤🫤

    Use :

    "Bitcoin Cash", "BCH", b"\x00", b"\x05", b"\x80"

    @dataclass
    class CoinConfig:
        """Configuration for different cryptocurrencies."""
    
        name: str
        symbol: str
        p2pkh_prefix: bytes
        p2sh_prefix: bytes
        wif_prefix: bytes
        bech32_hrp: Optional[str] = None
    
    
    # Cryptocurrency configurations
    COINS = {
        "btc": CoinConfig("Bitcoin", "BTC", b"\x00", b"\x05", b"\x80", "bc"),
        "ltc": CoinConfig("Litecoin", "LTC", b"\x30", b"\x32", b"\xb0", "ltc"),
        "doge": CoinConfig("Dogecoin", "DOGE", b"\x1e", b"\x16", b"\x9e"),
        "bch": CoinConfig("Bitcoin Cash", "BCH", b"\x00", b"\x05", b"\x80"),
        "dash": CoinConfig("Dash", "DASH", b"\x4c", b"\x10", b"\xcc"),
        "zcash": CoinConfig("Zcash", "ZEC", b"\x1c\xb8", b"\x1c\xbd", b"\x80"),
        "vtc": CoinConfig("Vertcoin", "VTC", b"\x47", b"\x05", b"\x80", "vtc"),
    }
    
    
    @dataclass
    class AddressSet:
        """Standard address set for cryptocurrencies."""
    
        legacy: str
        script: str
        segwit: Optional[str] = None
    
    
    @dataclass
    class WalletInfo:
        """Complete wallet information with professional structure."""
    
        private_key: str
        wif: str
        decimal: int
        addresses: AddressSet
        network: str
        compressed: bool = True
    
        def to_dict(self) -> Dict[str, Any]:
            """Convert to dictionary for backward compatibility."""
            return asdict(self)
    
        network: str
        compressed: bool = True
    
    
    class Crypto:
        """Universal cryptocurrency wallet generator with enhanced error handling."""
    
        def __init__(self, private_key: str, coin_type: str = "btc"):
            """
            Initialize crypto wallet with validation.
    
            Args:
                private_key: 64-character hex private key
                coin_type: Cryptocurrency type (btc, ltc, doge, bch, dash, zcash, vtc)
    
            Raises:
                ValueError: If private key format is invalid or coin type unsupported
            """
            if not isinstance(private_key, str):
                raise ValueError("Private key must be a string")
    
            # Remove 0x prefix if present
            if private_key.startswith("0x"):
                private_key = private_key[2:]
    
            if len(private_key) != 64:
                raise ValueError("Private key must be 64 hex characters")
    
            try:
                int(private_key, 16)
            except ValueError:
                raise ValueError("Private key must be valid hexadecimal")
    
            if coin_type not in COINS:
                raise ValueError(
                    f"Unsupported coin: {coin_type}. Supported: {list(COINS.keys())}"
                )
    
            self.private_key = private_key
            self.coin = COINS[coin_type]
            self.coin_type = coin_type
            self._private_key_bytes = bytes.fromhex(private_key)
            self._public_key = None
            self._public_key_uncompressed = None
    
        def _get_public_key(self, compressed: bool = True) -> bytes:
            """Get public key from private key with caching."""
            cache_key = "_public_key" if compressed else "_public_key_uncompressed"
    
            if getattr(self, cache_key, None) is None:
                try:
                    sk = ecdsa.SigningKey.from_string(
                        self._private_key_bytes, curve=ecdsa.SECP256k1
                    )
                    vk = sk.get_verifying_key()
    
                    if compressed:
                        prefix = b"\x02" if vk.pubkey.point.y() % 2 == 0 else b"\x03"
                        public_key = prefix + vk.to_string()[:32]
                    else:
                        public_key = b"\x04" + vk.to_string()
    
                    setattr(self, cache_key, public_key)
                except Exception as e:
                    raise ValueError(f"Failed to derive public key: {e}")
    
            return getattr(self, cache_key)
    
        def legacy(self, compressed: bool = True) -> str:
            """Get legacy P2PKH address (short name)."""
            return self.get_legacy_addr(compressed)
    
        def script(self, compressed: bool = True) -> str:
            """Get P2SH script address (short name)."""
            return self.get_script_addr(compressed)
    
        def get_legacy_addr(self, compressed: bool = True) -> str:
            """Get legacy P2PKH address."""
            try:
                public_key = self._get_public_key(compressed)
                hash160_result = hash160(public_key)
                versioned = self.coin.p2pkh_prefix + hash160_result
                return b58encode_check(versioned).decode("utf-8")
            except Exception as e:
                raise ValueError(f"Failed to generate legacy address: {e}")
    
        def get_script_addr(self, compressed: bool = True) -> str:
            """Get P2SH script address."""
            try:
                public_key = self._get_public_key(compressed)
                script = b"\x76\xa9\x14" + hash160(public_key) + b"\x88\xac"
                script_hash = hash160(script)
                versioned = self.coin.p2sh_prefix + script_hash
                return b58encode_check(versioned).decode("utf-8")
            except Exception as e:
                raise ValueError(f"Failed to generate script address: {e}")
    
        def wif(self, compressed: bool = True) -> str:
            """Get WIF format (short name)."""
            return self.get_wif(compressed)
    
        def decimal(self) -> int:
            """Get private key as decimal (short name)."""
            return self.get_decimal()
    
        def get_wif(self, compressed: bool = True) -> str:
            """Get WIF format."""
            try:
                if compressed:
                    extended = self.coin.wif_prefix + self._private_key_bytes + b"\x01"
                else:
                    extended = self.coin.wif_prefix + self._private_key_bytes
                return b58encode_check(extended).decode("utf-8")
            except Exception as e:
                raise ValueError(f"Failed to generate WIF: {e}")
    
        def get_decimal(self) -> int:
            """Get private key as decimal."""
            return int(self.private_key, 16)
    
        def addrs(self, compressed: bool = True) -> AddressSet:
            """Get all address types (short name)."""
            return self.get_addresses(compressed)
    
        def get_addresses(self, compressed: bool = True) -> AddressSet:
            """Get all address types."""
            return AddressSet(
                legacy=self.get_legacy_addr(compressed),
                script=self.get_script_addr(compressed),
                segwit=None,  # Not all coins support SegWit
            )
    
        def info(self, compressed: bool = True) -> WalletInfo:
            """Get complete wallet information (short name)."""
            return self.get_wallet_info(compressed)
    
        def get_wallet_info(self, compressed: bool = True) -> WalletInfo:
            """Get complete wallet information."""
            return WalletInfo(
                private_key=self.private_key,
                wif=self.get_wif(compressed),
                decimal=self.get_decimal(),
                addresses=self.get_addresses(compressed),
                network=self.coin.name,
                compressed=compressed,
            )
    
    
    class MultiWallet:
        """Multi-cryptocurrency wallet manager with enhanced features."""
    
        def __init__(self, private_key: Optional[str] = None):
            """
            Initialize with single private key for all networks.
    
            Args:
                private_key: Hex private key. If None, generates new one.
            """
            if private_key is None:
                private_key = gen_key()
    
            # Validate private key
            if private_key.startswith("0x"):
                private_key = private_key[2:]
    
            if len(private_key) != 64:
                raise ValueError("Private key must be 64 hex characters")
    
            try:
                int(private_key, 16)
            except ValueError:
                raise ValueError("Private key must be valid hexadecimal")
    
            self.private_key = private_key
            self._wallets = {}
            self._eth_wallet = None
            self._trx_wallet = None
    
        def btc(self, compressed: bool = True) -> WalletInfo:
            """Get Bitcoin wallet."""
            if "btc" not in self._wallets:
                self._wallets["btc"] = Crypto(self.private_key, "btc")
            return self._wallets["btc"].get_wallet_info(compressed)
    
        def ltc(self, compressed: bool = True) -> WalletInfo:
            """Get Litecoin wallet."""
            if "ltc" not in self._wallets:
                self._wallets["ltc"] = Crypto(self.private_key, "ltc")
            return self._wallets["ltc"].get_wallet_info(compressed)
    
        def doge(self, compressed: bool = True) -> WalletInfo:
            """Get Dogecoin wallet."""
            if "doge" not in self._wallets:
                self._wallets["doge"] = Crypto(self.private_key, "doge")
            return self._wallets["doge"].get_wallet_info(compressed)
    
        def bch(self, compressed: bool = True) -> WalletInfo:
            """Get Bitcoin Cash wallet."""
            if "bch" not in self._wallets:
                self._wallets["bch"] = Crypto(self.private_key, "bch")
            return self._wallets["bch"].get_wallet_info(compressed)
    
        def dash(self, compressed: bool = True) -> WalletInfo:
            """Get Dash wallet."""
            if "dash" not in self._wallets:
                self._wallets["dash"] = Crypto(self.private_key, "dash")
            return self._wallets["dash"].get_wallet_info(compressed)
    
        def zcash(self, compressed: bool = True) -> WalletInfo:
            """Get Zcash wallet."""
            if "zcash" not in self._wallets:
                self._wallets["zcash"] = Crypto(self.private_key, "zcash")
            return self._wallets["zcash"].get_wallet_info(compressed)
    
        def vtc(self, compressed: bool = True) -> WalletInfo:
            """Get Vertcoin wallet."""
            if "vtc" not in self._wallets:
                self._wallets["vtc"] = Crypto(self.private_key, "vtc")
            return self._wallets["vtc"].get_wallet_info(compressed)
    
        def eth(self) -> Dict[str, Any]:
            """Get Ethereum wallet."""
            if self._eth_wallet is None:
                try:
                    self._eth_wallet = Ethereum(self.private_key)
                except Exception as e:
                    raise ValueError(f"Failed to create Ethereum wallet: {e}")
    
            return {
                "private_key": self.private_key,
                "decimal": self._eth_wallet.get_decimal(),
                "address": self._eth_wallet.get_address(),
                "network": "Ethereum",
            }
    
        def trx(self) -> Dict[str, Any]:
            """Get Tron wallet."""
            if self._trx_wallet is None:
                try:
                    self._trx_wallet = tron(self.private_key)
                except Exception as e:
                    raise ValueError(f"Failed to create Tron wallet: {e}")
    
            return {
                "private_key": self.private_key,
                "decimal": self._trx_wallet.get_decimal(),
                "address": self._trx_wallet.get_address(),
                "hex_address": self._trx_wallet.get_hexAddress(),
                "evm_address": self._trx_wallet.get_evmAddress(),
                "network": "Tron",
            }
    
        def all_coins(self, compressed: bool = True) -> Dict[str, Any]:
            """Get wallets for all supported cryptocurrencies."""
            return {
                "btc": asdict(self.btc(compressed)),
                "ltc": asdict(self.ltc(compressed)),
                "doge": asdict(self.doge(compressed)),
                "bch": asdict(self.bch(compressed)),
                "dash": asdict(self.dash(compressed)),
                "zcash": asdict(self.zcash(compressed)),
                "vtc": asdict(self.vtc(compressed)),
                "eth": self.eth(),
                "trx": self.trx(),
            }
    
        def all(self, compressed: bool = True) -> Dict[str, Any]:
            """Get all wallets (short name)."""
            return self.all_coins(compressed)
    
    
    # Convenience functions with shorter names
    def gen_key() -> str:
        """Generate secure 256-bit private key."""
        return secrets.randbits(256).to_bytes(32, "big").hex()
    
    
    def multi_wallet(private_key: Optional[str] = None) -> MultiWallet:
        """Create multi-cryptocurrency wallet."""
        return MultiWallet(private_key)
    
    
    def btc_wallet(
        private_key: Optional[str] = None, compressed: bool = True
    ) -> WalletInfo:
        """Generate Bitcoin wallet."""
        if private_key is None:
            private_key = gen_key()
        return Crypto(private_key, "btc").get_wallet_info(compressed)
    
    
    def ltc_wallet(
        private_key: Optional[str] = None, compressed: bool = True
    ) -> WalletInfo:
        """Generate Litecoin wallet."""
        if private_key is None:
            private_key = gen_key()
        return Crypto(private_key, "ltc").get_wallet_info(compressed)
    
    
    def doge_wallet(
        private_key: Optional[str] = None, compressed: bool = True
    ) -> WalletInfo:
        """Generate Dogecoin wallet."""
        if private_key is None:
            private_key = gen_key()
        return Crypto(private_key, "doge").get_wallet_info(compressed)
    
    
    def bch_wallet(
        private_key: Optional[str] = None, compressed: bool = True
    ) -> WalletInfo:
        """Generate Bitcoin Cash wallet."""
        if private_key is None:
            private_key = gen_key()
        return Crypto(private_key, "bch").get_wallet_info(compressed)
    
    
    def dash_wallet(
        private_key: Optional[str] = None, compressed: bool = True
    ) -> WalletInfo:
        """Generate Dash wallet."""
        if private_key is None:
            private_key = gen_key()
        return Crypto(private_key, "dash").get_wallet_info(compressed)
    
    
    def zcash_wallet(
        private_key: Optional[str] = None, compressed: bool = True
    ) -> WalletInfo:
        """Generate Zcash wallet."""
        if private_key is None:
            private_key = gen_key()
        return Crypto(private_key, "zcash").get_wallet_info(compressed)
    
    
    def vtc_wallet(
        private_key: Optional[str] = None, compressed: bool = True
    ) -> WalletInfo:
        """Generate Vertcoin wallet."""
        if private_key is None:
            private_key = gen_key()
        return Crypto(private_key, "vtc").get_wallet_info(compressed)
    
    
    def eth_wallet(private_key: Optional[str] = None) -> Dict[str, Any]:
        """Generate Ethereum wallet."""
        if private_key is None:
            private_key = gen_key()
        try:
            eth = Ethereum(private_key)
            return {
                "private_key": private_key,
                "decimal": eth.get_decimal(),
                "address": eth.get_address(),
                "network": "Ethereum",
            }
        except Exception as e:
            raise ValueError(f"Failed to create Ethereum wallet: {e}")
    
    
    def trx_wallet(private_key: Optional[str] = None) -> Dict[str, Any]:
        """Generate Tron wallet."""
        if private_key is None:
            private_key = gen_key()
        try:
            trx = tron(private_key)
            return {
                "private_key": private_key,
                "decimal": trx.get_decimal(),
                "address": trx.get_address(),
                "hex_address": trx.get_hexAddress(),
                "evm_address": trx.get_evmAddress(),
                "network": "Tron",
            }
        except Exception as e:
            raise ValueError(f"Failed to create Tron wallet: {e}")
    
    
    # Bulk generation functions with enhanced error handling
    def gen_wallets(
        count: int, coin_type: str = "btc", compressed: bool = True
    ) -> List[WalletInfo]:
        """Generate multiple wallets for specified coin."""
        if count <= 0:
            raise ValueError("Count must be positive")
        if count > 10000:
            raise ValueError("Count too large (max 10000)")
        if coin_type not in COINS:
            raise ValueError(f"Unsupported coin: {coin_type}")
    
        wallets = []
        for _ in range(count):
            try:
                private_key = gen_key()
                wallet = Crypto(private_key, coin_type).get_wallet_info(compressed)
                wallets.append(wallet)
            except Exception as e:
                raise ValueError(f"Failed to generate wallet: {e}")
        return wallets
    
    
    def gen_multi_wallets(count: int, compressed: bool = True) -> List[Dict[str, Any]]:
        """Generate multiple multi-coin wallets."""
        if count <= 0:
            raise ValueError("Count must be positive")
        if count > 1000:
            raise ValueError("Count too large for multi-wallets (max 1000)")
    
        wallets = []
        for _ in range(count):
            try:
                private_key = gen_key()
                multi = MultiWallet(private_key)
                wallets.append(multi.all_coins(compressed))
            except Exception as e:
                raise ValueError(f"Failed to generate multi-wallet: {e}")
        return wallets
    
    

    BCH

        def bch(self, compressed: bool = True) -> WalletInfo:
            """Get Bitcoin Cash wallet."""
            if "bch" not in self._wallets:
                self._wallets["bch"] = Crypto(self.private_key, "bch")
            return self._wallets["bch"].get_wallet_info(compressed)

    Understand?

    Refrence : libit

  8. pbies commented on Feb 5, 2026

    @pbies

    @Pymmdrza I am already using BCH in HDWallet:

    from hdwallet import HDWallet
    from hdwallet.cryptocurrencies import BitcoinCash as BCH
    from hdwallet.hds import BIP32HD
    hdwallet = HDWallet(cryptocurrency=BCH, hd=BIP32HD)
    ...
    hdwallet.from_private_key(private_key=pvk)
    

    So what's your point?

  9. Pymmdrza commented on Feb 5, 2026

    @Pymmdrza
    Author

    @Pymmdrza I am already using BCH in HDWallet:

    from hdwallet import HDWallet
    from hdwallet.cryptocurrencies import BitcoinCash as BCH
    from hdwallet.hds import BIP32HD
    hdwallet = HDWallet(cryptocurrency=BCH, hd=BIP32HD)
    ...
    hdwallet.from_private_key(private_key=pvk)
    

    Use this : https://github.com/Pymmdrza/libcrypto

    hdwallet very very It's unconventional and no principles are followed, and after a few days you wake up and see that they completely changed the structure of the library, without paying attention to the users and programmers who used them in their projects. @meherett

  10. pbies commented on Feb 5, 2026

    @pbies

    @Pymmdrza yep, you are right. I've seen the mega-change in HDwallet and I needed to rework all my scripts. That's shouldn't take place. I now used another library for BCH but will try yours later as it seems promising.

  11. itsm3abena commented on Feb 5, 2026

    @itsm3abena
    Member

    Can you share us private key and address u expecting just to see the prefix, its for reference

  12. pbies commented on Feb 5, 2026

    @pbies

    @itsm3abena

    invalid:

    0000000000000000000000000000000000000000000000000000000000000001
    bitcoincash1qw508d6qejxtdg4y5r3zarvary0c5xw7k66a5um
    bitcoincash1q9qs9xv7mjghkd69fgx62xttxmeww5q7eekjxu0nxtzf4yu4ekf8sf8glp0
    

    valid:

    qp63uahgrxged4z5jswyt5dn5v3lzsem6cy4spdc2h
    
  13. meherett commented on Feb 5, 2026

    @meherett
    Collaborator

    @pbies Thanks for catching that - it’s fixed now: 201a7f1

    For now, please install the latest version directly from GitHub until the new package release is published:

    pip install git+ssh://github.com/hdwallet-io/python-hdwallet.git

    Example

    #!/usr/bin/env python3
    
    from hdwallet import HDWallet
    from hdwallet.cryptocurrencies import BitcoinCash as Cryptocurrency
    from hdwallet.consts import PUBLIC_KEY_TYPES
    from hdwallet.hds import BIP32HD
    
    import json
    
    hdwallet: HDWallet = HDWallet(
        cryptocurrency=Cryptocurrency,
        hd=BIP32HD,
        network=Cryptocurrency.NETWORKS.MAINNET,
        public_key_type=PUBLIC_KEY_TYPES.COMPRESSED
    ).from_private_key(
        private_key="0000000000000000000000000000000000000000000000000000000000000001"
    )
    
    print(json.dumps(hdwallet.dump(exclude={"indexes"}), indent=4, ensure_ascii=False))

    Output

    {
        "cryptocurrency": "Bitcoin-Cash",
        "symbol": "BCH",
        "network": "mainnet",
        "coin_type": 145,
        "entropy": null,
        "strength": null,
        "mnemonic": null,
        "passphrase": null,
        "language": null,
        "seed": null,
        "ecc": "SLIP10-Secp256k1",
        "hd": "BIP32",
        "semantic": "p2pkh",
        "root_xprivate_key": null,
        "root_xpublic_key": null,
        "root_private_key": null,
        "root_wif": null,
        "root_chain_code": null,
        "root_public_key": null,
        "strict": null,
        "public_key_type": "compressed",
        "wif_type": "wif-compressed",
        "derivation": {
            "xprivate_key": null,
            "xpublic_key": null,
            "private_key": "0000000000000000000000000000000000000000000000000000000000000001",
            "wif": "KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn",
            "chain_code": null,
            "public_key": "0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
            "uncompressed": "0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8",
            "compressed": "0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
            "hash": "751e76e8199196d454941c45d1b3a323f1433bd6",
            "fingerprint": "751e76e8",
            "parent_fingerprint": null,
            "addresses": {
                "std-bitcoincash": "bitcoincash:qp63uahgrxged4z5jswyt5dn5v3lzsem6cy4spdc2h",
                "std-p2pkh": "1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH",
                "std-p2sh": "4YSK54Y53wb45gfPWJyRf3EXqaRfbhfyao",
                "legacy-bitcoincash": "bitcoincash:qp63uahgrxged4z5jswyt5dn5v3lzsem6cy4spdc2h",
                "legacy-p2pkh": "1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH",
                "legacy-p2sh": "3LRW7jeCvQCRdPF8S3yUCfRAx4eqXFmdcr"
            }
        }
    }

    For a BitcoinCash address-only example, explore this https://github.com/hdwallet-io/python-hdwallet/blob/master/examples/addresses/slip10_secp256k1_address.py#L120

    Thanks!

  14. pbies commented on Feb 5, 2026

    @pbies

    @meherett yes, now it seems fixed, however I see different addresses, two sets:

    Set 1 in code:

    BitcoinCash
    P2PKH
    P2SH
    

    Set 2 in dump:

    std-bitcoincash
    std-p2pkh
    std-p2sh
    legacy-bitcoincash
    legacy-p2pkh
    legacy-p2sh
    

    How to access set 2 in code? These names don't fit for addresses...

  15. meherett commented on Feb 5, 2026

    @meherett
    Collaborator

    @pbies, the two sets are equivalent overall, but P2SH differs: STD and Legacy return different outputs. You can access all addresses like this:

    #!/usr/bin/env python3
    
    from hdwallet import HDWallet
    from hdwallet.cryptocurrencies import BitcoinCash as Cryptocurrency
    from hdwallet.consts import PUBLIC_KEY_TYPES
    from hdwallet.hds import BIP32HD
    
    hdwallet: HDWallet = HDWallet(
        cryptocurrency=Cryptocurrency,
        hd=BIP32HD,
        network=Cryptocurrency.NETWORKS.MAINNET,
        public_key_type=PUBLIC_KEY_TYPES.COMPRESSED
    ).from_private_key(
        private_key="0000000000000000000000000000000000000000000000000000000000000001"
    )
    
    print("BitcoinCash:", hdwallet.address(address=Cryptocurrency.ADDRESSES.BITCOINCASH))
    print("P2PKH:", hdwallet.address(address=Cryptocurrency.ADDRESSES.P2PKH))
    print("STD-P2SH:", hdwallet.address(
        address=Cryptocurrency.ADDRESSES.P2SH,
        address_type=Cryptocurrency.ADDRESS_TYPES.STD
    ))
    print("Legacy-P2SH:", hdwallet.address(
        address=Cryptocurrency.ADDRESSES.P2SH,
        address_type=Cryptocurrency.ADDRESS_TYPES.LEGACY
    ))

    Output

    BitcoinCash: bitcoincash:qp63uahgrxged4z5jswyt5dn5v3lzsem6cy4spdc2h
    P2PKH: 1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH
    STD-P2SH: 4YSK54Y53wb45gfPWJyRf3EXqaRfbhfyao
    Legacy-P2SH: 3LRW7jeCvQCRdPF8S3yUCfRAx4eqXFmdcr
  16. pbies commented on Feb 5, 2026

    @pbies

    @meherett
    Yes, thank you! These are valid and do not repeat:

    hdwallet.address(address=BCH.ADDRESSES.BITCOINCASH)[12:]
    hdwallet.address(address=BCH.ADDRESSES.P2PKH)
    hdwallet.address(address=BCH.ADDRESSES.P2SH, address_type=BCH.ADDRESS_TYPES.LEGACY)
    hdwallet.address(address=BCH.ADDRESSES.P2SH, address_type=BCH.ADDRESS_TYPES.STD)
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    addressenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions