-
I'm using Example 1: def generate_address(address_type: str) -> dict:
k = Key()
if address_type == '1':
addr = k.address(script_type='p2pkh') # Legacy address starting with 1
elif address_type == '3':
addr = k.address(script_type='p2sh') # P2SH address starting with 3
else: # bc1
addr = k.address(script_type='p2wpkh', encoding='bech32') # Native SegWit address starting with bc1
return {
'address': addr,
'private_key': k.wif(),
'public_key': k.public_hex
}
# Generate one of each type
for addr_type in ['1', '3', 'bc1']:
wallet = generate_address(addr_type)
print(wallet) Example 2: from bitcoinlib.keys import Key, Address
key = Key() # Generate a new private key
pubkey_hex = key.public_hex # Get the public key in hex format
# Create a P2SH address from the public key
address = Address(pubkey_hex, script_type='p2sh')
key_data = {
'private_key_wif': key.wif(),
'public_key_hex': pubkey_hex,
'address': address.address,
}
print(key_data) How I'm importing private keys: type '1':
type '3':
type 'bc1':
Version: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Use the same script_type 'p2sh_p2wpkh' in both Bitcoinlib and Electrum.
Import in Electrum: p2wpkh-p2sh:Kwzph4cjwh5jQFL31iMu7aXJrBkcSeYQ4a6Ydktg1KJVjX6Uvv9W |
Beta Was this translation helpful? Give feedback.
Use the same script_type 'p2sh_p2wpkh' in both Bitcoinlib and Electrum.
Import in Electrum: p2wpkh-p2sh:Kwzph4cjwh5jQFL31iMu7aXJrBkcSeYQ4a6Ydktg1KJVjX6Uvv9W
and addresses should be the same