1

Im trying to write a python script that can generate a new wallet for that user, but I need to be able to keep the private key.

I followed this : Stack overflow answer
And got these results:

import os
from ethereum import utils
key = utils.sha3(os.urandom(4096))
print key
Out[5]: 'L\xf7\x98\x06\xb9\xbe>?
c\x88\xd3\xa7\x05\xdd\xe8AtNe\xf3\xe7Pc\xed\xd8L~\\\xcc\rq\x18'
raw = utils.privtoaddr(key)
print raw
Out[7]: 
'n\x98V8\x05\xa1\x05\x9b\x18\xca%\xb3\xed\xd0\xd5\xa9I\xf8\x97\x15'
add = utils.checksum_encode(raw)
print add
Out[9]: '0x6e98563805A1059B18ca25B3edd0d5a949f89715'

So, I was able to get an address, but I'm not exactly sure what am I seeing here in the "key" and "raw" variables

Os is Ubuntu 16.4, running python 2.7.12
Note that this is a small personal project for learning, so I don't really mind any "security" issues

Edit: I was able to use this to create to do what I needed, I will leave this question open since Im still interested about my first way. https://github.com/vkobel/ethereum-generate-wallet

8

It looks like you're in Python 2. Py2 represents bytes in a latin-1 encoded string. Sometimes you'll see ascii characters, other times you'll see something like \x18 which means the byte 00011000, aka 18 in hex, or 24 as an integer. A private key is just a bunch of bytes back-to-back.

raw is the binary representation of the address. The address in addr is the hex string representation (with checksumming defined in EIP-55). Note the ending of the address: 15, which corresponds to \x15 in addr.


You may also be interested in web3.py v4 features for private key management: http://web3py.readthedocs.io/en/latest/web3.eth.account.html

It looks like:

>>> from web3.auto import w3
>>> acct = w3.eth.account.create('KEYSMASH FJAFJKLDSKF7JKFDJ 1530')
>>> acct.address
'0x5ce9454909639D2D17A3F753ce7d93fa0b9aB12E'
>>> acct.privateKey
b"\xb2\\}\xb3\x1f\xee\xd9\x12''\xbf\t9\xdcv\x9a\x96VK-\xe4\xc4rm\x03[6\xec\xf1\xe5\xb3d"

If you would like to see the hex encoding of the private key, you can use:

>>> acct.privateKey.hex()
'b25c7db31feed9122727bf0939dc769a96564b2de4c4726d035b36ecf1e5b364'
  • 1
    Thank you for the explanation. So now I am able to see the "actual" private key using .encode('hex') on the string :) – Ron Serruya Dec 12 '17 at 10:46
  • 1
    Well, we disagree about what "actual" means about the private key. :) I think the native bytes representation is the most natural representation. I'll add an extra note for people who want the hex version, though. – carver Oct 15 '18 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.