bnb-chain / bsc-docker

48 stars 31 forks source link

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

Open Muhammad-Altabba opened 10 months ago

Muhammad-Altabba commented 10 months ago

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 commented 10 months ago

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

Muhammad-Altabba commented 9 months ago

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

Muhammad-Altabba commented 9 months ago

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.