From 3491b5ae026bfe569728496aa73bdaf1b8a4d2ee Mon Sep 17 00:00:00 2001 From: Salief Date: Mon, 16 Oct 2023 13:56:26 -0400 Subject: [PATCH 1/2] add dotenv preloading to start script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8991d81..f3ad332 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "build": "tsc", - "start": "tsx src/server.ts", + "start": "tsx -r dotenv/config src/server.ts", "format": "biome format . --write" }, "keywords": [], From 38c0fee1c73b0a84ab36b62963f8dbac91c308da Mon Sep 17 00:00:00 2001 From: Salief Date: Mon, 16 Oct 2023 14:20:34 -0400 Subject: [PATCH 2/2] wip, env service config --- package.json | 2 +- src/config/clients.ts | 12 ++++-------- src/constants/riverNetSigner.ts | 7 ++----- src/services/index.ts | 1 + src/userOperations/createAndRegisterAccount.ts | 6 ++---- 5 files changed, 10 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index f3ad332..8991d81 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "build": "tsc", - "start": "tsx -r dotenv/config src/server.ts", + "start": "tsx src/server.ts", "format": "biome format . --write" }, "keywords": [], diff --git a/src/config/clients.ts b/src/config/clients.ts index 853353f..6cc5ef5 100644 --- a/src/config/clients.ts +++ b/src/config/clients.ts @@ -12,9 +12,7 @@ import { PublicClient, } from 'viem' import { riverNetSigner } from '@/constants' -import { config } from 'dotenv' - -config() +import { env } from '@/services' const chain = 'optimism-goerli' @@ -22,7 +20,7 @@ export const pimlicoBundlerClient = createClient({ chain: optimismGoerli, // ⚠️ using v1 of the API ⚠️ transport: http( - `https://api.pimlico.io/v1/${chain}/rpc?apikey=${process.env.PIMLICO_KEY}`, + `https://api.pimlico.io/v1/${chain}/rpc?apikey=${env.PIMLICO_KEY}`, ), }) .extend(bundlerActions) @@ -32,15 +30,13 @@ export const pimlicoPaymasterClient = createClient({ chain: optimismGoerli, // ⚠️ using v2 of the API ⚠️ transport: http( - `https://api.pimlico.io/v2/${chain}/rpc?apikey=${process.env.PIMLICO_KEY}`, + `https://api.pimlico.io/v2/${chain}/rpc?apikey=${env.PIMLICO_KEY}`, ), }).extend(pimlicoPaymasterActions) export const publicClient = createPublicClient({ chain: optimismGoerli, - transport: http( - `https://opt-goerli.g.alchemy.com/v2/${process.env.ALCHEMY_KEY}`, - ), + transport: http(`https://opt-goerli.g.alchemy.com/v2/${env.ALCHEMY_KEY}`), }) as PublicClient export const walletClient = createWalletClient({ diff --git a/src/constants/riverNetSigner.ts b/src/constants/riverNetSigner.ts index 4d2b967..d2049b8 100644 --- a/src/constants/riverNetSigner.ts +++ b/src/constants/riverNetSigner.ts @@ -1,9 +1,6 @@ import { privateKeyToAccount } from 'viem/accounts' import { type Hash } from 'viem' -import { config } from 'dotenv' +import { env } from '@/services' -config() -export const riverNetSigner = privateKeyToAccount( - process.env.PRIVATE_KEY as Hash, -) +export const riverNetSigner = privateKeyToAccount(env.PRIVATE_KEY as Hash) diff --git a/src/services/index.ts b/src/services/index.ts index c91810d..549b1bc 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -1 +1,2 @@ export * from './createAccount' +export * from './env' diff --git a/src/userOperations/createAndRegisterAccount.ts b/src/userOperations/createAndRegisterAccount.ts index 3b92f25..34f94ac 100644 --- a/src/userOperations/createAndRegisterAccount.ts +++ b/src/userOperations/createAndRegisterAccount.ts @@ -15,9 +15,7 @@ import { import { entryPoint, riverNetSigner, idRegistry } from '@/constants' import { idRegistryAbi, riverAccountAbi } from '@/abi' import { buildInitCode } from '@/helpers' -import { config } from 'dotenv' - -config() +import { env } from '@/services' export async function createAndRegisterAccount({ initialAdmin, @@ -78,7 +76,7 @@ export async function createAndRegisterAccount({ chainId: optimismGoerli.id, }), }, - privateKey: process.env.PRIVATE_KEY as Hash, + privateKey: env.PRIVATE_KEY as Hash, }) sponsoredUserOperation.signature = signature