feat: add support for private key authentication in environment configuration
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
MNEMONIC="{INSERT_12_WORD_MNEMONIC}"
|
||||
PRIVATE_KEY="{INSERT_0x_PRIVATE_KEY}"
|
||||
|
||||
INFURA_API_KEY="{INSERT_API_KEY}"
|
||||
ALCHEMY_API_KEY="{INSERT_API_KEY}"
|
||||
|
||||
@@ -67,7 +67,11 @@
|
||||
|
||||
### 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
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ const mnemonic: string =
|
||||
process.env.MNEMONIC ?? DEFAULT_MNEMONIC;
|
||||
const alchemyApiKey: string | undefined =
|
||||
process.env.ALCHEMY_API_KEY;
|
||||
const privateKey: string | undefined =
|
||||
process.env.PRIVATE_KEY;
|
||||
|
||||
const chainIds = {
|
||||
// "{INSERT_NAME}": {INSERT_ID},
|
||||
@@ -43,11 +45,13 @@ function getChainConfig(
|
||||
const jsonRpcUrl =
|
||||
"https://" + chain + ".g.alchemy.com/v2/" + alchemyApiKey;
|
||||
return {
|
||||
accounts: {
|
||||
count: 10,
|
||||
mnemonic,
|
||||
path: "m/44'/60'/0'/0",
|
||||
},
|
||||
accounts: privateKey
|
||||
? [privateKey]
|
||||
: {
|
||||
count: 10,
|
||||
mnemonic,
|
||||
path: "m/44'/60'/0'/0",
|
||||
},
|
||||
chainId: chainIds[chain],
|
||||
url: jsonRpcUrl,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user