Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Executing python3 private-key.py gives AttributeError: 'Account' object has no attribute 'privateKeyToAccount' #14

Open
Muhammad-Altabba opened this issue Nov 6, 2023 · 3 comments · May be fixed by #16

Comments

@Muhammad-Altabba
Copy link

Muhammad-Altabba commented Nov 6, 2023

I am trying to run for dev environment on Linux machine.
I found the steps are bit confusing for just running for a dev env. Additionally when I run python3 private-key.py it gives

Traceback (most recent call last):
File "/home/maltabba/repos/experiments/bsc/bsc-docker/private-key.py", line 13, in
acct = w3.eth.account.privateKeyToAccount(private_key)
AttributeError: 'Account' object has no attribute 'privateKeyToAccount'

What do you suggest?
Thanks,

@STdevK
Copy link

STdevK commented Nov 8, 2023

Can you run the command from "init-holders" folder?

@Muhammad-Altabba
Copy link
Author

It produced the exact same error when running from inside init-holders.

@Muhammad-Altabba
Copy link
Author

Muhammad-Altabba commented Nov 21, 2023

Updating the content of private-key.py to the following resolved the issue:

#!/usr/bin/env python3

from web3 import Web3, HTTPProvider
import os

private_keys = './init-holders'
idx = 1
w3 = Web3(HTTPProvider('http://localhost:8545', request_kwargs={'timeout': 120}))
for keystore_file in os.listdir(private_keys):
    with open("%s/%s" % (private_keys, keystore_file)) as keyfile:
        encrypted_file = keyfile.read()
        private_key = w3.eth.account.decrypt(encrypted_file, '')
        acct = w3.eth.account.from_key(private_key)
        print('Account %s: %s, private key: %s' % (idx, Web3.to_checksum_address(acct.address), private_key.hex()))
        idx = idx + 1
    

I opened a PR for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants