Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create an ethereum wallet in pure python?

I am building an application that would create a wallet for a user. One option is the web3.personal API in web3.py, which has a newAccount('passphrase') method. The method only returns the address of created account.

What I'm looking for is a function similar to the eth.accounts API in web3.js, which has a create([entropy]) method. It returns an account object with 'address', 'privatekey' and other details.

I am very new to the idea of ethereum and such kind of development practice, so would be glad to get some help from you. Thank you in advance.

like image 629
Saujanya Acharya Avatar asked Sep 01 '17 16:09

Saujanya Acharya


1 Answers

Edit: I removed the deprecated pyethereum solution, replaced with the better eth-account one.

Setup

At shell: pip install eth_account

Generating Account

The eth-account library will help you create a private key with an attached address:

>>> from eth_account import Account

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

Adding some of your own randomness above helps address potential limitations of os.urandom, which depends on your version of Python, and your operating system. Obviously use a different string of randomness than the 'KEYSMASH...' one from above.

For more information about using the private key, see this doc with common examples, like signing a transaction.


As a side-note, you may find more support at ethereum.stackexchange.com

like image 81
carver Avatar answered Oct 15 '22 06:10

carver