From c4db98ae00da1d9dadd3d6fe6b25e7dfcc0ed819 Mon Sep 17 00:00:00 2001 From: Arthur Abeilice Date: Fri, 29 May 2026 17:48:49 -0300 Subject: [PATCH] feat: add support for private key authentication in environment configuration --- .env.example | 1 + README.md | 6 +++++- hardhat.config.ts | 14 +++++++++----- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.env.example b/.env.example index d972d67..d51532c 100644 --- a/.env.example +++ b/.env.example @@ -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}" diff --git a/README.md b/README.md index 1dc3c8a..a71cfaa 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/hardhat.config.ts b/hardhat.config.ts index 80b961d..99845ec 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -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, };