| 1 | import { addEnsContracts } from "@ensdomains/ensjs"; |
| 2 | import { createPublicClient, createWalletClient, http } from "viem"; |
| 3 | import { mainnet } from "viem/chains"; |
| 4 | import { privateKeyToAccount } from "viem/accounts"; |
| 5 | |
| 6 | export const ensClient = createPublicClient({ |
| 7 | chain: { |
| 8 | ...addEnsContracts(mainnet), |
| 9 | subgraphs: { ens: { url: "https://api.alpha.ensnode.io/subgraph" } }, |
| 10 | }, |
| 11 | transport: http(process.env.ETH_RPC_URL || "https://eth.drpc.org"), |
| 12 | }); |
| 13 | |
| 14 | export async function walletClient() { |
| 15 | const privateKey = process.env.ATLAS_PRIVATE_KEY; |
| 16 | |
| 17 | if (!privateKey) { |
| 18 | return null; |
| 19 | } |
| 20 | |
| 21 | const account = privateKeyToAccount(privateKey as `0x${string}`); |
| 22 | |
| 23 | return createWalletClient({ |
| 24 | account, |
| 25 | chain: addEnsContracts(mainnet), |
| 26 | transport: http(process.env.ETH_RPC_URL || "https://eth.drpc.org"), |
| 27 | }); |
| 28 | } |