bitcoinlib.networks module
- class bitcoinlib.networks.Network(network_name='bitcoin')[source]
Bases:
objectNetwork class with all network definitions.
Prefixes for WIF, P2SH keys, HD public and private keys, addresses. A currency symbol and type, the denominator (such as satoshi) and a BIP0044 cointype.
- wif_prefix(is_private=False, witness_type='legacy', multisig=False)[source]
Get WIF prefix for this network and specifications in arguments
>>> Network('bitcoin').wif_prefix() # xpub b'\x04\x88\xb2\x1e' >>> Network('bitcoin').wif_prefix(is_private=True, witness_type='segwit', multisig=True) # Zprv b'\x02\xaaz\x99'
- Parameters:
is_private (bool) – Private or public key, default is True
witness_type (str) – Legacy, segwit or p2sh-segwit
multisig (bool) – Multisignature or single signature wallet. Default is False: no multisig
- Return bytes:
- exception bitcoinlib.networks.NetworkError(msg='')[source]
Bases:
ExceptionNetwork Exception class
- bitcoinlib.networks.network_by_value(field, value)[source]
Return all networks for field and (prefix) value.
Example, get available networks for WIF or address prefix
>>> network_by_value('prefix_wif', 'B0') ['litecoin', 'litecoin_legacy'] >>> network_by_value('prefix_address', '6f') ['testnet', 'testnet4', 'signet', 'litecoin_testnet']
This method does not work for HD prefixes, use ‘wif_prefix_search’ instead
>>> network_by_value('prefix_address', '043587CF') []
- Parameters:
field (str) – Prefix name from networks definitions (networks.json)
value (str) – Value of network prefix
- Return list:
Of network name strings
- bitcoinlib.networks.network_defined(network)[source]
Is network defined?
Networks of this library are defined in networks.json in the operating systems user path.
>>> network_defined('bitcoin') True >>> network_defined('ethereum') False
- Parameters:
network (str) – Network name
- Return bool:
- bitcoinlib.networks.network_values_for(field)[source]
Return all prefixes for field, i.e.: prefix_wif, prefix_address_p2sh, etc
>>> network_values_for('prefix_wif') [b'\x99', b'\x80', b'\xef', b'\xb0', b'\x9e', b'\xf1'] >>> network_values_for('prefix_address_p2sh') [b'\x95', b'\x05', b'\xc4', b'2', b':', b'\x16']
- Parameters:
field (str) – Prefix name from networks definitions (networks.json)
- Return str:
- bitcoinlib.networks.wif_prefix_search(wif, witness_type=None, multisig=None, network=None)[source]
Extract network, script type and public/private information from HDKey WIF or WIF prefix.
Example, get bitcoin ‘xprv’ info:
>>> wif_prefix_search('0488ADE4', network='bitcoin', multisig=False) [{'prefix': '0488ADE4', 'is_private': True, 'prefix_str': 'xprv', 'network': 'bitcoin', 'witness_type': 'legacy', 'multisig': False, 'script_type': 'p2pkh'}]
Or retreive info with full WIF string:
>>> wif_prefix_search('xprv9wTYmMFdV23N21MM6dLNavSQV7Sj7meSPXx6AV5eTdqqGLjycVjb115Ec5LgRAXscPZgy5G4jQ9csyyZLN3PZLxoM1h3BoPuEJzsgeypdKj', network='bitcoin', multisig=False) [{'prefix': '0488ADE4', 'is_private': True, 'prefix_str': 'xprv', 'network': 'bitcoin', 'witness_type': 'legacy', 'multisig': False, 'script_type': 'p2pkh'}]
Can return multiple items if no network is specified:
>>> [nw['network'] for nw in wif_prefix_search('0488ADE4', multisig=True)] ['bitcoin', 'regtest', 'dogecoin']
- Parameters:
wif (str) – WIF string or prefix as hexadecimal string
witness_type (str) – Limit search to specific witness type
multisig (bool) – Limit search to multisig: false, true or None for both. Default is both
network (str) – Limit search to specified network
- Return dict: