pywallet icon indicating copy to clipboard operation
pywallet copied to clipboard

How to get private key from ethereum wallet?

Open zaza316614 opened this issue 6 years ago • 5 comments

This package is good to me. Using this package, I generated ethereum wallet. Here, private key is as follow. 0488ade4039c7ed931800000009f85cde1810467f199d7e0b6b2edaa6bc2f960b66ea61af9e35477c50e2243da00494c713bd615f7bef54adca9292cbd86e9f077e6a0ee33553258a2d961793a4e

But when I send transaction using web3.py, required private key has 32 bytes long. Above key is too long. I can't use this. How can I get private key to be required to send transaction? Help me.

zaza316614 avatar Jun 02 '18 13:06 zaza316614

I spent a while looking through the code and I also couldn't figure out...

lightclient avatar Jun 03 '18 05:06 lightclient

Any update on this?

aazout avatar Nov 02 '18 23:11 aazout

Had the same issue, install this library and use the code below to get the actual private key:

from crypto import HDPrivateKey, HDKey, PrivateKey


def decode(pkey_hex):
    assert len(pkey_hex) == 156
    pkey = HDPrivateKey.from_hex(pkey_hex)
    keys = HDKey.from_path(pkey, '{change}/{index}'.format(change=0, index=0))
    private_key = keys[-1]
    public_key = private_key.public_key
    print('  Private key (hex, compressed): 0x' + private_key._key.to_hex())
    print('  Address: ' + private_key.public_key.address())


def main():
    keys = [
        '0488ade4039c7ed931800000009f85cde1810467f199d7e0b6b2edaa6bc2f960b66ea61af9e35477c50e2243da00494c713bd615f7bef54adca9292cbd86e9f077e6a0ee33553258a2d961793a4e'
    ]
    for k in keys:
        decode(k)


if __name__ == '__main__':
    main()

hurlenko avatar Nov 15 '18 08:11 hurlenko

Hello @hurlenko Not working for me.

    from Crypto.Util.py3compat import byte_string
ImportError: cannot import name 'byte_string'

henrytom1703 avatar Dec 19 '18 03:12 henrytom1703

Hi @henrytom1703, I used python 3.6, worked for me. Create new virtual environment, git clone this repo, run pip install -r requirements.txt then try again

hurlenko avatar Dec 19 '18 16:12 hurlenko