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

Extract private key from keystore file. #441

Closed
Skyge opened this issue Apr 23, 2020 · 3 comments
Closed

Extract private key from keystore file. #441

Skyge opened this issue Apr 23, 2020 · 3 comments

Comments

@Skyge
Copy link
Contributor

Skyge commented Apr 23, 2020

I am trying to use keystore file to send a transaction, and I find the code is:

with json_file.open() as fp:
    priv_key = web3.eth.account.decrypt(
        json.load(fp), getpass("Enter the password to unlock this account: ")
     }

I am not sure when we try to use the function web3.eth.account.decrypt(), whether it will connect to a node or not, but I know the package: eth_account, it just extracts the private locally, so is there a need to use eth_account to replace web3.eth.account at here?

@iamdefinitelyahuman
Copy link
Member

There is no need to use web3 directly. After adding the keystore to Brownie, you can access it using Accounts.load. For example, if you add the keystore using the ID owner as shown in the example in #440, you can then import it with:

acct = Accounts.load('owner')

acct is a LocalAccount object which has an identical API to the Account objects you are already familiar with.

Related documentation:

@Skyge
Copy link
Contributor Author

Skyge commented Apr 23, 2020

Ohhh, so even though we use the function web3.eth.account.decrypt(), this is a off-line method, it will not connect a node.

@Skyge
Copy link
Contributor Author

Skyge commented Apr 25, 2020

Close the issue, cause it seems like the function web3.eth.account.decrypt() in the web3 and the function Accounts.decrypt() in the eth_account return the same result.

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

No branches or pull requests

2 participants