[Ethereum] Python ethereum create account using web3.py


I am trying to create account for a user using web3.py in my local testrpc ethereum network. I have tried as per the documentation. But I am getting the error

AttributeError: 'Eth' object has no attribute 'account'

Code I am trying :

from web3 import Web3
acct = w3.eth.account.create('KEYSMASH FJAFJKLDSKF7JKFDJ 1530')

I could see there is accounts object in for eth object but that is not what I need.

What am I doing wrong ? I could see there is another type of account which is called PersonalAccount in the doc

What is the difference between these two ?

Best Answer

Update: web3.py v4 has been stable for a while, so the question and answer don't really make sense anymore. w3.eth.account is included in any modern install.

In order to use the latest w3.eth.account feature, you will have to either:

  • Wait for the v4 beta to come out (in the next week or so)
  • Install web3.py from source

Installing from source

git clone https://github.com/pipermerriam/web3.py.git
cd web3.py

virtualenv -p python3 venv
. venv/bin/activate

pip install -e .
>>> from web3 import Web3, ...

Documentation Info

The web3 documentation you're referring to is for "latest", which corresponds to the source code on master at http://github.com/pipermerriam/web3.py

To see what features are available in v3, see the stable web3 documentation instead.

Related Topic