bsc-docker icon indicating copy to clipboard operation
bsc-docker copied to clipboard

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

Open Muhammad-Altabba opened this issue 1 year ago • 3 comments

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,

Muhammad-Altabba avatar Nov 06 '23 07:11 Muhammad-Altabba

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

STdevK avatar Nov 08 '23 18:11 STdevK

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

Muhammad-Altabba avatar Nov 21 '23 10:11 Muhammad-Altabba

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.

Muhammad-Altabba avatar Nov 21 '23 10:11 Muhammad-Altabba