-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
272 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { HttpTransport, PublicClient, createPublicClient, http } from "viem"; | ||
|
||
import { chains } from "../chains"; | ||
import type { SUPPORTED_CHAINS } from "../chains"; | ||
|
||
export const getPublicClient = (): PublicClient<HttpTransport, typeof chains[SUPPORTED_CHAINS]> => { | ||
const chainName = process.env.FORKED_NETWORK as SUPPORTED_CHAINS; | ||
return createPublicClient({ | ||
chain: chains[chainName], | ||
transport: http(process.env[`LIVE_NETWORK_${chainName}`]), | ||
}); | ||
}; | ||
|
||
export default getPublicClient(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { HttpTransport, WalletClient, createWalletClient, http } from "viem"; | ||
import { PrivateKeyAccount, privateKeyToAccount } from "viem/accounts"; | ||
|
||
import { chains } from "../chains"; | ||
import type { SUPPORTED_CHAINS } from "../chains"; | ||
|
||
const readPrivateKeyFromEnv = (chainName: string): PrivateKeyAccount => { | ||
const key = process.env[`PRIVATE_KEY_${chainName}`]; | ||
if (key?.startsWith("0x")) { | ||
return privateKeyToAccount(key as `0x${string}`); | ||
} | ||
throw new Error(`Invalid private key for ${chainName}. Please specify PRIVATE_KEY_${chainName} env variable.`); | ||
}; | ||
|
||
export const getWalletClient = (): WalletClient<HttpTransport, typeof chains[SUPPORTED_CHAINS], PrivateKeyAccount> => { | ||
const chainName = process.env.FORKED_NETWORK as SUPPORTED_CHAINS; | ||
return createWalletClient({ | ||
chain: chains[chainName], | ||
transport: http(process.env[`LIVE_NETWORK_${chainName}`]), | ||
account: readPrivateKeyFromEnv(chainName), | ||
}); | ||
}; | ||
|
||
export default getWalletClient(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.