diff --git a/brownie/network/account.py b/brownie/network/account.py index 2aa3d4dcd..b32e3c6da 100644 --- a/brownie/network/account.py +++ b/brownie/network/account.py @@ -842,13 +842,14 @@ def __init__(self, address: str, account: Account, priv_key: Union[int, bytes, s self.public_key = eth_keys.keys.PrivateKey(HexBytes(priv_key)).public_key super().__init__(address) - def save(self, filename: str, overwrite: bool = False) -> str: + def save(self, filename: str, overwrite: bool = False, password: Optional[str] = None) -> str: """Encrypts the private key and saves it in a keystore json. Attributes: filename: path to keystore file. If no folder is given, saved in ~/.brownie/accounts overwrite: if True, will overwrite an existing file. + password: Password used to encrypt the account. If none, you will be prompted Returns the absolute path to the keystore file as a string. """ @@ -863,9 +864,11 @@ def save(self, filename: str, overwrite: bool = False) -> str: json_file = Path(filename).expanduser().resolve() if not overwrite and json_file.exists(): raise FileExistsError("Account with this identifier already exists") - encrypted = web3.eth.account.encrypt( - self.private_key, getpass("Enter the password to encrypt this account with: ") - ) + + if password is None: + password = getpass("Enter the password to encrypt this account with: ") + + encrypted = web3.eth.account.encrypt(self.private_key, password) with json_file.open("w") as fp: json.dump(encrypted, fp) return str(json_file)