You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An example how to manage local private key using env (#2380)
* An example how to manage local private key using env
How to manage private keys using environment variable, how to generate them, and some security warnings.
* Fix extra period
Inserted by the editor?
* add content tweaks and newsfragment
Co-authored-by: Marc Garreau <[email protected]>
This private key is then added to the transaction signing keychain
64
+
with ``Signing`` middleware.
65
+
66
+
If unfamiliar, note that you can `export your private keys from Metamask and other wallets <https://metamask.zendesk.com/hc/en-us/articles/360015289632-How-to-Export-an-Account-Private-Key>`_.
67
+
68
+
.. warning ::
69
+
70
+
- **Never** share your private keys.
71
+
- **Never** put your private keys in source code.
72
+
- **Never** commit private keys to a Git repository.
73
+
74
+
Example ``account_test_script.py``
75
+
76
+
.. code-block:: python
77
+
78
+
import os
79
+
from eth_account import Account
80
+
from eth_account.signers.local import LocalAccount
81
+
from web3.auto import w3
82
+
from web3.middleware import construct_sign_and_send_raw_middleware
83
+
84
+
private_key = os.environ.get("PRIVATE_KEY")
85
+
assert private_key isnotNone, "You must set PRIVATE_KEY environment variable"
86
+
assert private_key.startswith("0x"), "Private key must start with 0x hex prefix"
0 commit comments