feat: add support for private key authentication in environment configuration
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
MNEMONIC="{INSERT_12_WORD_MNEMONIC}"
|
MNEMONIC="{INSERT_12_WORD_MNEMONIC}"
|
||||||
|
PRIVATE_KEY="{INSERT_0x_PRIVATE_KEY}"
|
||||||
|
|
||||||
INFURA_API_KEY="{INSERT_API_KEY}"
|
INFURA_API_KEY="{INSERT_API_KEY}"
|
||||||
ALCHEMY_API_KEY="{INSERT_API_KEY}"
|
ALCHEMY_API_KEY="{INSERT_API_KEY}"
|
||||||
|
|||||||
@@ -67,7 +67,11 @@
|
|||||||
|
|
||||||
### Pre Requisites
|
### Pre Requisites
|
||||||
|
|
||||||
Before installing, create a `.env` file and set a BIP-39 compatible mnemonic and other env criteria as in `.env.example`.
|
Before installing, create a `.env` file and set the authentication method and other env criteria as in `.env.example`.
|
||||||
|
|
||||||
|
You can authenticate with either:
|
||||||
|
- `PRIVATE_KEY` — a raw hex private key (e.g. `0x123...`). Takes priority if both are set.
|
||||||
|
- `MNEMONIC` — a BIP-39 compatible 12-word mnemonic phrase. Used as fallback when `PRIVATE_KEY` is not set.
|
||||||
|
|
||||||
### Install
|
### Install
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ const mnemonic: string =
|
|||||||
process.env.MNEMONIC ?? DEFAULT_MNEMONIC;
|
process.env.MNEMONIC ?? DEFAULT_MNEMONIC;
|
||||||
const alchemyApiKey: string | undefined =
|
const alchemyApiKey: string | undefined =
|
||||||
process.env.ALCHEMY_API_KEY;
|
process.env.ALCHEMY_API_KEY;
|
||||||
|
const privateKey: string | undefined =
|
||||||
|
process.env.PRIVATE_KEY;
|
||||||
|
|
||||||
const chainIds = {
|
const chainIds = {
|
||||||
// "{INSERT_NAME}": {INSERT_ID},
|
// "{INSERT_NAME}": {INSERT_ID},
|
||||||
@@ -43,7 +45,9 @@ function getChainConfig(
|
|||||||
const jsonRpcUrl =
|
const jsonRpcUrl =
|
||||||
"https://" + chain + ".g.alchemy.com/v2/" + alchemyApiKey;
|
"https://" + chain + ".g.alchemy.com/v2/" + alchemyApiKey;
|
||||||
return {
|
return {
|
||||||
accounts: {
|
accounts: privateKey
|
||||||
|
? [privateKey]
|
||||||
|
: {
|
||||||
count: 10,
|
count: 10,
|
||||||
mnemonic,
|
mnemonic,
|
||||||
path: "m/44'/60'/0'/0",
|
path: "m/44'/60'/0'/0",
|
||||||
|
|||||||
Reference in New Issue
Block a user