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>?
raw = utils.privtoaddr(key)
print raw
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

1 Answer 1


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
>>> acct.privateKey

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

>>> acct.privateKey.hex()
  • 1
    Thank you for the explanation. So now I am able to see the "actual" private key using .encode('hex') on the string :) Commented Dec 12, 2017 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
    Commented Oct 15, 2018 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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