zpywallet package

Subpackages

Submodules

zpywallet.bip38 module

class Bip38PrivateKey(privkey: PrivateKey, passphrase, compressed=True, segwit=False, witness_version=0)[source]

Bases: object

Represents a BIP38 encrypted private key for Bitcoin.

BLOCK_SIZE = 16
IV_LEN = 16
KEY_LEN = 32
__init__(privkey: PrivateKey, passphrase, compressed=True, segwit=False, witness_version=0)[source]

Creates a BIP0038 private key with non-ec-multiply encryption.

Parameters:
  • privkey (PrivateKey) – The private key.

  • passphrase (_type_) – The encryption passphrase

  • compressed (bool, optional) – Whether to use compressed public keys. Defaults to True.

  • segwit (bool, optional) – Whether to use segwit address. Defaults to False.

  • witness_version (int, optional) – The witness version for generating the segwit address. Defaults to 0.

Raises:

ValueError – If the private key object does not support Base58 or Bech32.

property base58

Returns the Base58 representation of the encrypted private key.

private_key(passphrase, compressed=True, segwit=False, witness_version=0)[source]

Decrypts the encrypted private key using the given passphrase and returns the corresponding WIF private key.

Parameters:
  • passphrase (_type_) – The passphrase to decrypt the key.

  • compressed (bool, optional) – Whether to use compressed public keys. Defaults to True.

  • segwit (bool, optional) – Whether to use segwit address. Defaults to False.

  • witness_version (int, optional) – The witness version for generating the segwit address. Defaults to 0.

Raises:

ValueError – If the wrong decryption passphrase was supplied.

Returns:

a Bitcoin private key.

Return type:

PrivateKey

decrypt(enc, passphrase)[source]

Decrypts encrypted data with a passphrase.

This method should only be used for calculating BIP38 data. It uses AES settings that are not ideal for general-purpose use.

Parameters:
  • enc (bytes) – The encrypted text to decrypt.

  • passphrase (str) – The passphrase used for decryption.

Returns:

The decrypted text.

Return type:

bytes

encrypt(raw, passphrase)[source]

Encrypts data with a passphrase.

This method should only be used for calculating BIP38 data. It uses AES settings that are not ideal for general-purpose use.

Parameters:
  • raw (str) – The text to encrypt.

  • passphrase (str) – The passphrase used for encryption.

Returns:

The encrypted text.

Return type:

bytes

zpywallet.destination module

class Destination(address, amount, network, fee_policy=FeePolicy.NONE, in_standard_units=True)[source]

Bases: object

Represents a destination address and amount to send.

__init__(address, amount, network, fee_policy=FeePolicy.NONE, in_standard_units=True)[source]

Initializes a Destination object.

Parameters:
  • address (str) – The destination address.

  • amount (int) – The amount of the destination.

  • network – The network associated with the destination.

  • fee_policy (FeePolicy, optional) – The fee policy associated with the destination. Defaults to FeePolicy.NONE.

  • in_standard_units (bool, optional) – If True, amount is in BTC/ETH-style standard units. If False, amount is already in sats/wei.

address()[source]

Returns the destination address.

amount(in_standard_units=True)[source]

Returns the amount of the destination.

Parameters:

in_standard_units (bool, optional) – If True, returns the amount in standard units. If False, returns the amount in the lowest denomination. Defaults to True.

fee_policy()[source]

Returns the fee policy associated with the destination.

script_pubkey()[source]

Returns the script public key associated with the destination.

class FeePolicy(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumeration representing fee policies.

FeePolicy.NONE: Indicates no fee policy. FeePolicy.PROPORTIONAL: Indicates a proportional fee policy.

NONE = 0
PROPORTIONAL = 1

zpywallet.errors module

exception ChecksumException[source]

Bases: Exception

Raised when the generated checksum of an address or public key does not match the expected checksum.

exception IncompatibleNetworkException[source]

Bases: Exception

Raised when importing a piece of network data into the wrong network.

exception InvalidChildException[source]

Bases: Exception

Raised when an invalid child key is passed.

exception InvalidPathError[source]

Bases: Exception

Raised when the provided derivation path is invalid.

exception KeyParseError[source]

Bases: Exception

exception NetworkException[source]

Bases: Exception

Raised when a network request fails.

exception PublicKeyHashException[source]

Bases: Exception

Raised when attempting a public key operation with a public key hash.

exception SegwitError[source]

Bases: Exception

Raised when a network does not support Segwit (P2WPKH).

exception WatchOnlyWalletError[source]

Bases: Exception

Raised when a wallet does not contain a private key when performing an operation that requires a public key.

incompatible_network_bytes_exception_factory(network_name, expected_prefix, given_prefix)[source]

A factory function for IncompatibleNetworkException.

unsupported_feature_exception_factory(network_name, feature)[source]

Another factory function for IncompatibleNetworkException.

zpywallet.network module

This file contains parameters and constants for all supported networks.

class BitcoinCashMainNet[source]

Bases: CryptoNetwork

Bitcoin Cash MainNet version bytes.

ADDRESS_MODE = ['BASE58']
BECH32_PREFIX = None
BIP32_PATH = "m/44'/145'/0'"
BIP32_SEGWIT_PATH = None
CHAIN_ID = None
COIN = 'BCH'
EXT_PUBLIC_KEY = 76067358
EXT_SECRET_KEY = 76066276
EXT_SEGWIT_PUBLIC_KEY = None
EXT_SEGWIT_SECRET_KEY = None
INTERNAL_NAME = 19
NAME = 'Bitcoin Cash'
PUBKEY_ADDRESS = 28
SCRIPT_ADDRESS = 40
SECRET_KEY = 128
SUPPORTS_EVM = False
SUPPORTS_SEGWIT = False
TESTNET = False
class BitcoinMainNet[source]

Bases: CryptoNetwork

Bitcoin MainNet version bytes defaulting to legacy addresses. From https://github.com/bitcoin/bitcoin/blob/v0.9.0rc1/src/chainparams.cpp

ADDRESS_MODE = ['BASE58']
BECH32_PREFIX = None
BIP32_PATH = "m/44'/0'/0'"
BIP32_SEGWIT_PATH = None
CHAIN_ID = None
COIN = 'BTC'
EXT_PUBLIC_KEY = 76067358
EXT_SECRET_KEY = 76066276
EXT_SEGWIT_PUBLIC_KEY = None
EXT_SEGWIT_SECRET_KEY = None
INTERNAL_NAME = 1
NAME = 'Bitcoin'
PUBKEY_ADDRESS = 0
SCRIPT_ADDRESS = 5
SECRET_KEY = 128
SUPPORTS_EVM = False
SUPPORTS_SEGWIT = False
TESTNET = False
class BitcoinP2PKMainNet[source]

Bases: BitcoinMainNet

Bitcoin MainNet version bytes, with no address support - P2PK only.

ADDRESS_MODE = []
INTERNAL_NAME = 21
PUBKEY_ADDRESS = None
SCRIPT_ADDRESS = None
class BitcoinP2PKTestNet[source]

Bases: BitcoinTestNet

Bitcoin TestNet version bytes, with no address support - P2PK only.

ADDRESS_MODE = []
INTERNAL_NAME = 22
PUBKEY_ADDRESS = None
SCRIPT_ADDRESS = None
class BitcoinSegwitMainNet[source]

Bases: BitcoinMainNet

Bitcoin MainNet version bytes, defaulting to segwit addresses.

ADDRESS_MODE = ['BECH32', 'BASE58']
BECH32_PREFIX = 'bc'
BIP32_SEGWIT_PATH = "m/84'/0'/0'"
EXT_SEGWIT_PUBLIC_KEY = 78792518
EXT_SEGWIT_SECRET_KEY = 78791436
INTERNAL_NAME = 0
SUPPORTS_SEGWIT = True
class BitcoinSegwitTestNet[source]

Bases: BitcoinTestNet

Bitcoin TestNet version bytes, defaulting to segwit addresses.

ADDRESS_MODE = ['BECH32', 'BASE58']
BECH32_PREFIX = 'tb'
BIP32_SEGWIT_PATH = "m/84'/1'/0'"
EXT_SEGWIT_PUBLIC_KEY = 73342198
EXT_SEGWIT_SECRET_KEY = 73341116
INTERNAL_NAME = 2
SUPPORTS_SEGWIT = True
class BitcoinTestNet[source]

Bases: CryptoNetwork

Bitcoin TestNet version bytes, defaulting to legacy addresses. From https://github.com/bitcoin/bitcoin/blob/v0.9.0rc1/src/chainparams.cpp

ADDRESS_MODE = ['BASE58']
BECH32_PREFIX = None
BIP32_PATH = "m/44'/1'/0'"
BIP32_SEGWIT_PATH = None
CHAIN_ID = None
COIN = 'BTC'
EXT_PUBLIC_KEY = 70617039
EXT_SECRET_KEY = 70615956
EXT_SEGWIT_PUBLIC_KEY = None
EXT_SEGWIT_SECRET_KEY = None
INTERNAL_NAME = 3
NAME = 'Bitcoin'
PUBKEY_ADDRESS = 111
SCRIPT_ADDRESS = 196
SECRET_KEY = 239
SUPPORTS_EVM = False
SUPPORTS_SEGWIT = False
TESTNET = True
class BlockcypherTestNet[source]

Bases: CryptoNetwork

Blockcypher TestNet version bytes. From http://dev.blockcypher.com/#testing

ADDRESS_MODE = ['BASE58']
BECH32_PREFIX = None
BIP32_PATH = "m/44'/1'/0'"
BIP32_SEGWIT_PATH = None
CHAIN_ID = None
COIN = 'BCY'
EXT_PUBLIC_KEY = 47453183
EXT_SECRET_KEY = 47452099
EXT_SEGWIT_PUBLIC_KEY = None
EXT_SEGWIT_SECRET_KEY = None
INTERNAL_NAME = 20
NAME = 'BlockCypher'
PUBKEY_ADDRESS = 27
SCRIPT_ADDRESS = 31
SECRET_KEY = 73
SUPPORTS_EVM = False
SUPPORTS_SEGWIT = False
class CryptoNetwork[source]

Bases: object

Represents a cryptocurrency blockchain.

Don’t use this class - use one of the subclasses instead.

P2PKH_TESTNET_PATH = "m/44'/1'/0'"
class DashBTCMainNet[source]

Bases: CryptoNetwork

Dash MainNet version bytes.

Extended version bytes are the same as for Bitcoin, i.e. xpub/xprv, for maximum wallet compatibility.

ADDRESS_MODE = ['BASE58']
BECH32_PREFIX = None
BIP32_PATH = "m/44'/5'/0'"
BIP32_SEGWIT_PATH = None
CHAIN_ID = None
COIN = 'DASH'
EXT_PUBLIC_KEY = 76067358
EXT_SECRET_KEY = 76066276
EXT_SEGWIT_PUBLIC_KEY = None
EXT_SEGWIT_SECRET_KEY = None
INTERNAL_NAME = 16
NAME = 'Dash'
PUBKEY_ADDRESS = 76
SCRIPT_ADDRESS = 16
SECRET_KEY = 204
SUPPORTS_EVM = False
SUPPORTS_SEGWIT = False
TESTNET = False
class DashInvertedMainNet[source]

Bases: DashMainNet

Dash MainNet version bytes.

This is the version that uses drkv/drkp as the public/private extended version bytes respectively. It intentionally has the same name and coin as the other Dash mainnets.

EXT_PUBLIC_KEY = 50221816
EXT_SECRET_KEY = 50221772
INTERNAL_NAME = 15
class DashInvertedTestNet[source]

Bases: DashTestNet

Dash TestNet version bytes with inverted extended version bytes.

EXT_PUBLIC_KEY = 981492128
EXT_SECRET_KEY = 981489719
INTERNAL_NAME = 18
class DashMainNet[source]

Bases: CryptoNetwork

Dash MainNet version bytes.

Dash’s xpub/xprv were originally drkp/drkv. But somehow, they were swapped when inserted into the refernece client. So there are actually two possible combinations of addresses in Dash (3, if you also count Bitcoin’s xpub/xprv)

For more information, see the following link: https://www.dash.org/forum/index.php?threads/dash-bip32-serialization-values-dev-discussion-wont-apply-to-most.8092/

ADDRESS_MODE = ['BASE58']
BECH32_PREFIX = None
BIP32_PATH = "m/44'/5'/0'"
BIP32_SEGWIT_PATH = None
CHAIN_ID = None
COIN = 'DASH'
EXT_PUBLIC_KEY = 50221772
EXT_SECRET_KEY = 50221816
EXT_SEGWIT_PUBLIC_KEY = None
EXT_SEGWIT_SECRET_KEY = None
INTERNAL_NAME = 14
NAME = 'Dash'
PUBKEY_ADDRESS = 76
SCRIPT_ADDRESS = 16
SECRET_KEY = 204
SUPPORTS_EVM = False
SUPPORTS_SEGWIT = False
TESTNET = False
class DashTestNet[source]

Bases: CryptoNetwork

Dash TestNet version bytes.

ADDRESS_MODE = ['BASE58']
BECH32_PREFIX = None
BIP32_PATH = "m/44'/1'/0'"
BIP32_SEGWIT_PATH = None
CHAIN_ID = None
COIN = 'DASH'
EXT_PUBLIC_KEY = 981489719
EXT_SECRET_KEY = 981492128
EXT_SEGWIT_PUBLIC_KEY = None
EXT_SEGWIT_SECRET_KEY = None
INTERNAL_NAME = 17
NAME = 'Dash'
PUBKEY_ADDRESS = 140
SCRIPT_ADDRESS = 19
SECRET_KEY = 239
SUPPORTS_EVM = False
SUPPORTS_SEGWIT = False
TESTNET = True
class DogecoinBTCMainNet[source]

Bases: CryptoNetwork

Dogecoin MainNet version bytes

Primary version bytes from: https://github.com/dogecoin/dogecoin/blob/1.5.2/src/base58.h

Extended version bytes are the same as for Bitocin mainnet, i.e. xpub/xprv, for wallet compatibility.

ADDRESS_MODE = ['BASE58']
BECH32_PREFIX = None
BIP32_PATH = "m/44'/3'/0'"
BIP32_SEGWIT_PATH = None
CHAIN_ID = None
COIN = 'DOGE'
EXT_PUBLIC_KEY = 49990397
EXT_SECRET_KEY = 49988504
EXT_SEGWIT_PUBLIC_KEY = None
EXT_SEGWIT_SECRET_KEY = None
INTERNAL_NAME = 12
NAME = 'Dogecoin'
PUBKEY_ADDRESS = 30
SCRIPT_ADDRESS = 22
SECRET_KEY = 158
SUPPORTS_EVM = False
SUPPORTS_SEGWIT = False
TESTNET = False
class DogecoinMainNet[source]

Bases: CryptoNetwork

Dogecoin MainNet version bytes

Primary version bytes from: https://github.com/dogecoin/dogecoin/blob/1.5.2/src/base58.h

Unofficial extended version bytes from https://bitcointalk.org/index.php?topic=409731

ADDRESS_MODE = ['BASE58']
BECH32_PREFIX = None
BIP32_PATH = "m/44'/3'/0'"
BIP32_SEGWIT_PATH = None
CHAIN_ID = None
COIN = 'DOGE'
EXT_PUBLIC_KEY = 49990397
EXT_SECRET_KEY = 49988504
EXT_SEGWIT_PUBLIC_KEY = None
EXT_SEGWIT_SECRET_KEY = None
INTERNAL_NAME = 11
NAME = 'Dogecoin'
PUBKEY_ADDRESS = 30
SCRIPT_ADDRESS = 22
SECRET_KEY = 158
SUPPORTS_EVM = False
SUPPORTS_SEGWIT = False
TESTNET = False
class DogecoinTestNet[source]

Bases: CryptoNetwork

Dogecoin TestNet version bytes

Primary version bytes from: https://github.com/dogecoin/dogecoin/blob/1.5.2/src/base58.h

Unofficial extended version bytes from https://bitcointalk.org/index.php?topic=409731

ADDRESS_MODE = ['BASE58']
BECH32_PREFIX = None
BIP32_PATH = "m/44'/1'/0'"
BIP32_SEGWIT_PATH = None
CHAIN_ID = None
COIN = 'DOGE'
EXT_PUBLIC_KEY = 70429096
EXT_SECRET_KEY = 70427203
EXT_SEGWIT_PUBLIC_KEY = None
EXT_SEGWIT_SECRET_KEY = None
INTERNAL_NAME = 13
NAME = 'Dogecoin'
PUBKEY_ADDRESS = 113
SCRIPT_ADDRESS = 196
SECRET_KEY = 241
SUPPORTS_EVM = False
SUPPORTS_SEGWIT = False
TESTNET = True
class EthereumMainNet[source]

Bases: CryptoNetwork

Ethereum MainNet version bytes.

ADDRESS_MODE = ['HEX']
BECH32_PREFIX = None
BIP32_PATH = "m/44'/60'/0'"
BIP32_SEGWIT_PATH = None
CHAIN = 'main'
CHAIN_ID = 1
COIN = 'ETH'
EXT_PUBLIC_KEY = 76067358
EXT_SECRET_KEY = 76066276
EXT_SEGWIT_PUBLIC_KEY = None
EXT_SEGWIT_SECRET_KEY = None
INTERNAL_NAME = 10
NAME = 'Ethereum'
PUBKEY_ADDRESS = None
SCRIPT_ADDRESS = None
SECRET_KEY = None
SUPPORTS_EVM = True
SUPPORTS_SEGWIT = False
TESTNET = False
class EthereumSepoliaTestNet[source]

Bases: EthereumMainNet

Ethereum Sepolia TestNet version bytes.

CHAIN = 'sepolia'
CHAIN_ID = 11155111
INTERNAL_NAME = 23
NAME = 'Ethereum Sepolia'
TESTNET = True
class LitecoinBTCMainNet[source]

Bases: CryptoNetwork

Litecoin MainNet version bytes

Primary version bytes from: https://github.com/litecoin-project/litecoin/blob/master-0.8/src/base58.h

Extended version bytes same as bitcoin’s

ADDRESS_MODE = ['BASE58']
BECH32_PREFIX = None
BIP32_PATH = "m/44'/2'/0'"
BIP32_SEGWIT_PATH = None
CHAIN_ID = None
COIN = 'LTC'
EXT_PUBLIC_KEY = 76067358
EXT_SECRET_KEY = 76066276
EXT_SEGWIT_PUBLIC_KEY = None
EXT_SEGWIT_SECRET_KEY = None
INTERNAL_NAME = 7
NAME = 'Litecoin'
PUBKEY_ADDRESS = 48
SCRIPT_ADDRESS = 5
SECRET_KEY = 176
SUPPORTS_EVM = False
SUPPORTS_SEGWIT = False
TESTNET = False
class LitecoinBTCSegwitMainNet[source]

Bases: LitecoinBTCMainNet

Litecoin MainNet version bytes, defaulting to segwit addresses.

ADDRESS_MODE = ['BECH32', 'BASE58']
BECH32_PREFIX = 'ltc'
BIP32_SEGWIT_PATH = "m/84'/2'/0'"
EXT_SEGWIT_PUBLIC_KEY = 78792518
EXT_SEGWIT_SECRET_KEY = 78791436
INTERNAL_NAME = 6
SUPPORTS_SEGWIT = True
class LitecoinMainNet[source]

Bases: CryptoNetwork

Litecoin MainNet version bytes

Primary version bytes from: https://github.com/litecoin-project/litecoin/blob/master-0.8/src/base58.h

Extemded version bytes from https://bitcointalk.org/index.php?topic=453395.0

ADDRESS_MODE = ['BASE58']
BECH32_PREFIX = None
BIP32_PATH = "m/44'/2'/0'"
BIP32_SEGWIT_PATH = None
CHAIN_ID = None
COIN = 'LTC'
EXT_PUBLIC_KEY = 27108450
EXT_SECRET_KEY = 27106558
EXT_SEGWIT_PUBLIC_KEY = None
EXT_SEGWIT_SECRET_KEY = None
INTERNAL_NAME = 5
NAME = 'Litecoin'
PUBKEY_ADDRESS = 48
SCRIPT_ADDRESS = 5
SECRET_KEY = 176
SUPPORTS_EVM = False
SUPPORTS_SEGWIT = False
TESTNET = False
class LitecoinSegwitMainNet[source]

Bases: LitecoinMainNet

Litecoin MainNet version bytes, defaulting to segwit addresses.

ADDRESS_MODE = ['BECH32', 'BASE58']
BECH32_PREFIX = 'ltc'
BIP32_SEGWIT_PATH = "m/84'/2'/0'"
EXT_SEGWIT_PUBLIC_KEY = 78792518
EXT_SEGWIT_SECRET_KEY = 78791436
INTERNAL_NAME = 4
SUPPORTS_SEGWIT = True
class LitecoinSegwitTestNet[source]

Bases: LitecoinTestNet

Litecoin TestNet version bytes, defaulting to segwit addresses.

ADDRESS_MODE = ['BECH32', 'BASE58']
BECH32_PREFIX = 'tltc'
BIP32_SEGWIT_PATH = "m/84'/1'/0'"
EXT_SEGWIT_PUBLIC_KEY = 73342198
EXT_SEGWIT_SECRET_KEY = 73341116
INTERNAL_NAME = 5
SUPPORTS_SEGWIT = True
class LitecoinTestNet[source]

Bases: CryptoNetwork

Litecoin TestNet version bytes

Primary version bytes from: https://github.com/litecoin-project/litecoin/blob/master-0.8/src/base58.h

Litecoin testnet extended version bytes for legacy are the same as for Bitcoin testnet so we will just reuse the segwit for Bitcoin testnet as well. There is no official document I could find that supports this though.

ADDRESS_MODE = ['BASE58']
BECH32_PREFIX = None
BIP32_PATH = "m/44'/1'/0'"
BIP32_SEGWIT_PATH = None
CHAIN_ID = None
COIN = 'LTC'
EXT_PUBLIC_KEY = 70711009
EXT_SECRET_KEY = 70709117
EXT_SEGWIT_PUBLIC_KEY = None
EXT_SEGWIT_SECRET_KEY = None
INTERNAL_NAME = 5
NAME = 'Litecoin'
PUBKEY_ADDRESS = 111
SCRIPT_ADDRESS = 196
SECRET_KEY = 239
SUPPORTS_EVM = False
SUPPORTS_SEGWIT = False
TESTNET = True

zpywallet.transaction module

class Transaction(transaction: Transaction, network)[source]

Bases: object

Represents a transaction with associated metadata.

__init__(transaction: Transaction, network)[source]

Initializes a Transaction object.

Parameters:
  • transaction (wallet_pb2.Transaction) – The transaction protobuf message.

  • network – The network associated with the transaction.

confirmed()[source]

Returns a boolean indicating if the transaction is confirmed.

evm_amount(in_standard_units=True)[source]

Returns the amount transferred in the transaction (EVM).

Parameters:

in_standard_units (bool, optional) – If True, returns the amount in standard units. If False, returns the amount in the lowest denomination. Defaults to True.

evm_data()[source]

Returns the data associated with the transaction (EVM).

evm_from()[source]

Returns the sender address of the transaction (EVM).

evm_gas()[source]

Returns the gas used in the transaction (EVM).

evm_to()[source]

Returns the recipient address of the transaction (EVM).

height()[source]

Returns the block height of the transaction.

network()[source]

Returns the network associated with the transaction.

static normalize_evm_txid(txid)[source]
sat_feerate()[source]

Returns the fee rate of the transaction (Bitcoin-like).

sat_inputs(include_witness=False)[source]

Returns the inputs of the transaction (Bitcoin-like).

Parameters:

include_witness (bool, optional) – If True, includes witness data. Defaults to False.

sat_outputs(only_unspent=False)[source]

Returns the outputs of the transaction (Bitcoin-like).

Parameters:

only_unspent (bool, optional) – If True, returns only unspent outputs. Defaults to False.

timestamp()[source]

Returns the timestamp of the transaction.

total_fee(in_standard_units=True)[source]

Returns the total fee of the transaction.

Parameters:

in_standard_units (bool, optional) – If True, returns the fee in standard units. If False, returns the fee in the lowest denomination. Defaults to True.

txid()[source]

Returns the transaction ID.

zpywallet.utxo module

class UTXO(transaction: Transaction, index: int, other_transactions=None, addresses=None, only_mine=False, only_unspent=True, _internal_param_do_not_use=None, _network=None)[source]

Bases: object

Represents an Unspent Transaction Output (UTXO) associated with a transaction.

NOTE: Currently, UTXO can only detect compressed/uncompressed P2PKH (legacy “1”) and compressed P2WPKH (bech32 “bc1q”) addresses.

__init__(transaction: Transaction, index: int, other_transactions=None, addresses=None, only_mine=False, only_unspent=True, _internal_param_do_not_use=None, _network=None)[source]

Initializes a UTXO object.

Parameters:
  • transaction (Transaction) – The transaction associated with the UTXO.

  • index (int) – The index of the UTXO in the transaction outputs.

  • other_transactions (list, optional) – Other transactions related to the UTXO. Defaults to None.

  • addresses (list, optional) – Addresses associated with the UTXO. Defaults to None.

  • only_mine (bool, optional) – If True, only includes UTXOs belonging to the specified addresses. Defaults to False.

_addresshash()[source]

Returns the script pubkey associated with the UTXO (for internal use only).

_nsequence()[source]

Returns the sequence number associated with the UTXO (for internal use only).

_private_key()[source]

Returns the private key associated with the UTXO (for internal use only).

address()[source]

Returns the address associated with the UTXO.

amount(in_standard_units=True)[source]

Returns the amount of the UTXO.

Parameters:

in_standard_units (bool, optional) – If True, returns the amount in standard units. If False, returns the amount in the lowest denomination. Defaults to True.

height()[source]

Returns the block height of the UTXO.

index()[source]

Returns the index of the UTXO.

is_legacy()[source]

Returns whether this UTXO is for a legacy input.

network()[source]

Returns the network associated with the UTXO.

spent()[source]

Returns whether this transaction output has already been spent.

txid()[source]

Returns the transaction ID of the UTXO.

zpywallet.wallet module

This module contains the methods for creating a crypto wallet.

class Wallet(network, seed_phrase, password, receive_gap_limit=1000, change_gap_limit=None, derivation_path=None, _with_wallet=True, max_cycles=100, **kwargs)[source]

Bases: object

Data class representing a cryptocurrency wallet.

__init__(network, seed_phrase, password, receive_gap_limit=1000, change_gap_limit=None, derivation_path=None, _with_wallet=True, max_cycles=100, **kwargs)[source]

Initializes a Wallet object.

Parameters:
  • network – The network associated with the wallet.

  • seed_phrase – The seed phrase for the wallet.

  • password – The password to encrypt the wallet.

  • receive_gap_limit (int, optional) – The maximum gap limit for receive addresses. Defaults to 1000.

  • change_gap_limit (int, optional) – The maximum gap limit for change addresses. Defaults to the receive gap limit.

  • derivation_path (str, optional) – The derivation path for the wallet. Defaults to None.

  • max_cycles (int, optional) – The maximum number of cycles. Defaults to 100.

  • fullnode_endpoints (list, optional) – List of full node endpoints. Defaults to None.

  • esplora_endpoints (list, optional) – List of Esplora endpoints. Defaults to None.

  • blockcypher_tokens (list, optional) – List of Blockcypher tokens. Defaults to None.

Raises:

ValueError – If an unknown network is provided or if the derivation path is invalid.

addresses()[source]

Get the addresses associated with the wallet.

Returns:

The list of addresses associated with the wallet.

Return type:

List[str]

broadcast_transaction(transaction)[source]

Broadcast a transaction to the network.

Parameters:

transaction – The transaction to broadcast.

create_transaction(password: bytes, destinations: List[Destination], fee_rate=None, spend_unconfirmed_inputs=False, **kwargs)[source]

Create a transaction.

Parameters:
  • password (bytes) – The password used to encrypt the wallet.

  • destinations (List[Destination]) – The list of destinations for the transaction.

  • fee_rate – The fee rate for the transaction.

  • spend_unconfirmed_inputs (bool, optional) – If True, spend unconfirmed inputs. Defaults to False.

Returns:

The created transaction.

Return type:

Transaction

classmethod deserialize(data: bytes, password, max_cycles=100, **kwargs)[source]

Deserialize a Wallet object from its byte representation.

Parameters:
  • cls – The class object.

  • data (bytes) – The byte representation of the Wallet object.

  • password – The password used to encrypt the wallet.

  • max_cycles (int, optional) – The maximum number of cycles. Defaults to 100.

Returns:

The deserialized Wallet object.

Return type:

Wallet

Raises:

ValueError – If an unknown network is encountered during deserialization.

get_balance(in_standard_units=True)[source]

Get the balance of the wallet.

Parameters:

in_standard_units (bool, optional) – If True, balance is returned in standard units (e.g., BTC, ETH). If False, balance is returned in raw units (e.g., satoshi, wei). Defaults to True.

Returns:

The total balance and confirmed balance of the wallet.

Return type:

Tuple[float, float]

get_transaction_history()[source]

Get the transaction history associated with the wallet.

Returns:

The list of transactions in the wallet’s history.

Return type:

List[Transaction]

get_utxos(only_unspent=False)[source]

Get the unspent transaction outputs (UTXOs) associated with the wallet.

Parameters:

only_unspent (bool, optional) – If True, only unspent UTXOs are retrieved. Defaults to False.

Returns:

The list of unspent transaction outputs.

Return type:

List[UTXO]

network()[source]

Get the network associated with the wallet.

Returns:

The network associated with the wallet.

Return type:

CryptoNetwork

private_keys(password)[source]

Get the private keys associated with the wallet.

Parameters:

password – The password used to encrypt the wallet.

Returns:

The list of private keys associated with the wallet.

Return type:

List[str]

random_address()[source]

Get a random address from the wallet.

Returns:

A randomly selected address from the wallet.

Return type:

str

serialize()[source]

Serialize the wallet object.

Returns:

The serialized representation of the wallet.

Return type:

bytes

create_keypair(network=<class 'zpywallet.network.BitcoinSegwitMainNet'>)[source]

Generates a random private/public keypair.

Args: :param network: The network to create this wallet for

Returns:

a tuple of a private key and public key.

Return type:

PrivateKey, PublicKey

Usage:

w = create_wallet(network=’BTC’, children=10)

create_wallet(mnemonic=None, network=<class 'zpywallet.network.BitcoinSegwitMainNet'>, strength=128) HDWallet[source]

Deprecated: This function will be removed in v1.0

Generate a new wallet class from a mnemonic phrase, optionally randomly generated

Args:

Parameters:
  • mnemonic – The key to use to generate this wallet. It may be a long string. Do not use a phrase from a book or song, as that will be guessed and is not secure. My advice is to not supply this argument and let me generate a new random key for you.

  • network – The network to create this wallet for

  • children – Create this many child addresses for this wallet. Default is 10, You should not use the master private key itself for sending or receiving funds, as a best practice.

Returns:

a wallet class

Return type:

HDWallet

Usage:

w = create_wallet(network=’BTC’, children=10)

generate_mnemonic(strength=128)[source]

Creates a new seed phrase of the specified length

Module contents