Open deveshaggrawal19 opened 6 years ago
Please help me find the keys so that the generated address can be used. I am not able to figure it out.
This code is for generating addresses from an XPUB. When generating from an XPUB, you are only able to derive the public key and the address and not the corresponding private key.
acct_pub_key = HDKey.from_b58check('xpub6DKMR7KpgCJbiN4TdzcqcB1Nk84D9bsYUBhbk43EjRqH4RTjz7UgGLZxcQ4JdHBSHDmTUDLApMwYHRQCbbMCPQEtcbVofZEQjFazpGPT1nW') keys = HDKey.from_path(acct_pub_key,'{change}/{index}'.format(change=0, index=0)) public_key = keys[-1] print('Public key (hex, uncompressed): ' + public_key.to_hex()) print('Account address: ' + public_key.address())
If you're starting from the mnemonic, however, you can get the private key and public key:
master_key = HDPrivateKey.master_key_from_mnemonic('laundry snap patient survey sleep strategy finger bone real west arch protect') root_keys = HDKey.from_path(master_key,"m/44'/60'/0'") acct_priv_key = root_keys[-1] keys = HDKey.from_path(acct_priv_key,'{change}/{index}'.format(change=0, index=0)) private_key = keys[-1] public_key = private_key.public_key print("Private key (hex): " + private_key.to_hex()) print("Public key (hex, uncompressed): " + public_key.to_hex()) print("Address: " + private_key.public_key.address())
Hope that helps!
How can I get 64 characters private key or wif to sign a transaction?
@csbadhe Hmmm, it looks like my example above is giving the hex representation of the HDPrivateKey object. It looks like if you keep everything the same as above, this should give the actual private key:
print("Private key (hex): " + private_key._key.to_hex())
It worked. Thanks a lot, @michailbrynard.
Thanks for making such a good module for. Can you tell me how to get private and public keys to the generated address?