0

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 w3 = Web3(YOUR_PROVIDER) 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 ?

Bill Goldberg
  • 241
  • 1
  • 3
  • 8

2 Answers2

1

There are multiple Ethereum libraries for Python, try using this one https://github.com/pipermerriam/web3.py I didn't have good luck with the consensus one.

The docs list eth.account.create http://web3py.readthedocs.io/en/latest/web3.eth.account.html

git clone git@github.com:pipermerriam/web3.py.git

cd web3.py

virtualenv venv .

venv/bin/activate

pip install -r requirements-dev.txt

pip install -e .

python from web3 import Web3

web3 = Web3(HTTPProvider('http://localhost:8545'))

web3.eth.account.create("asdf")

  • Thanks Matthew. We are using the pipermerriam only. The doc link I have specified above is of same. – Bill Goldberg Nov 14 '17 at 06:50
  • I added a bigger sample. Its likely you have wrong web3 in your virtual env. See above if you do the sample above this works web3.eth.account.create("asdf") however it doesn't work in my global python cause of a wrong dependency – Matthew Campbell Nov 14 '17 at 09:33
  • No I have the correct web3 I think. I even tried with

    pip install web3==3.16.1 on a seperate virtualenv.

    I am getting the below error while running pip install -e . python from web3 import Web3

    No matching distribution found for python
    
    – Bill Goldberg Nov 14 '17 at 10:08
  • Did you try the Singular Account? web3.eth.account.create("asdf") – Matthew Campbell Nov 14 '17 at 14:24
  • I could not complete the steps you mentioned. As in the above comment. Failed on the pip install -e . python from web3 import Web3 step. – Bill Goldberg Nov 14 '17 at 14:46
  • Those are two separate lines, stack overflow formats horribly see above now – Matthew Campbell Nov 14 '17 at 15:24
1

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 .
python
>>> 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.

carver
  • 6,381
  • 21
  • 51
  • Thanks. That is now clear. Could you please answer my another question ? The difference between account & personal account ? – Bill Goldberg Nov 14 '17 at 17:55
  • Check out this answer for a full breakdown: https://ethereum.stackexchange.com/questions/25601/what-is-the-difference-between-web3-eth-sign-web3-eth-accounts-sign-web3-eth-p/25610#25610 – carver Nov 14 '17 at 21:23