How to create an ethereum wallet in pure python?

I am creating 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 returns only the address of the created account.

I am looking for a function similar to the eth.accounts API in web3.js that 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 a development practice, so I would be glad to receive some help from you. Thank you in advance.

+5
source share
1 answer

If you want to generate all these fragments locally in python, you can use pyethereum .

Customization

Shell: pip install ethereum

Generate Private Key

The private key is just a random series of 32 bytes. Create a large random byte string and take sha3.

 from ethereum import utils import os private_key = utils.sha3(os.urandom(4096)) 

Note. Please check out the os.urandom security os.urandom , which depends on your version of Python and your operating system.

Account address

Convert the private key to a shared address.

 raw_address = utils.privtoaddr(private_key) account_address = utils.checksum_encode(raw_address) 

As an additional note, you can find additional support at ethereum.stackexchange.com

+8
source

Source: https://habr.com/ru/post/1271432/


All Articles