diff --git a/cli/client/collect-escrow.ts b/cli/client/collect-escrow.ts index ab3f889..5cad394 100644 --- a/cli/client/collect-escrow.ts +++ b/cli/client/collect-escrow.ts @@ -8,11 +8,11 @@ import { parseArgs } from "util"; import { createWalletClient, http, publicActions } from "viem"; import { privateKeyToAccount } from "viem/accounts"; -import { foundry } from "viem/chains"; import { existsSync, readFileSync } from "fs"; import { resolve, dirname, join } from "path"; import { fileURLToPath } from "url"; import { makeClient } from "alkahest-ts"; +import { getChainFromNetwork } from "../utils.js"; // Get the directory of the current module const __filename = fileURLToPath(import.meta.url); @@ -148,6 +148,7 @@ async function main() { const deployment = JSON.parse(readFileSync(resolvedDeploymentPath, "utf-8")); const rpcUrl = args["rpc-url"] || deployment.rpcUrl; + const chain = getChainFromNetwork(deployment.network); console.log("🚀 Collecting Natural Language Agreement Escrow\n"); console.log("Configuration:"); @@ -159,7 +160,7 @@ async function main() { const account = privateKeyToAccount(privateKey as `0x${string}`); const walletClient = createWalletClient({ account, - chain: foundry, + chain, transport: http(rpcUrl), }).extend(publicActions); diff --git a/cli/client/create-escrow.ts b/cli/client/create-escrow.ts index ca42aec..c705c11 100644 --- a/cli/client/create-escrow.ts +++ b/cli/client/create-escrow.ts @@ -9,7 +9,6 @@ import { parseArgs } from "util"; import { createWalletClient, http, publicActions, parseEther } from "viem"; import { privateKeyToAccount } from "viem/accounts"; -import { foundry } from "viem/chains"; import { existsSync, readFileSync } from "fs"; import { resolve, dirname, join } from "path"; import { fileURLToPath } from "url"; @@ -17,6 +16,7 @@ import { makeClient } from "alkahest-ts"; import { makeLLMClient } from "../.."; import {fixtures} from "alkahest-ts"; import { getCurrentEnvironment } from "../commands/switch.js"; +import { getChainFromNetwork } from "../utils.js"; // Get the directory of the current module const __filename = fileURLToPath(import.meta.url); @@ -198,6 +198,7 @@ Fulfillment: {{obligation}}`; const deployment = JSON.parse(readFileSync(resolvedDeploymentPath, "utf-8")); const rpcUrl = args["rpc-url"] || deployment.rpcUrl; + const chain = getChainFromNetwork(deployment.network); console.log("🚀 Creating Natural Language Agreement Escrow\n"); console.log("Configuration:"); @@ -205,13 +206,14 @@ Fulfillment: {{obligation}}`; console.log(` 💰 Amount: ${amount} tokens`); console.log(` 🪙 Token: ${tokenAddress}`); console.log(` ⚖️ Oracle: ${oracleAddress}`); + console.log(` 🌐 Network: ${deployment.network}`); console.log(` 🌐 RPC URL: ${rpcUrl}\n`); // Create account and wallet const account = privateKeyToAccount(privateKey as `0x${string}`); const walletClient = createWalletClient({ account, - chain: foundry, + chain, transport: http(rpcUrl), }).extend(publicActions); diff --git a/cli/client/fulfill-escrow.ts b/cli/client/fulfill-escrow.ts index f91e5e0..1b8e073 100644 --- a/cli/client/fulfill-escrow.ts +++ b/cli/client/fulfill-escrow.ts @@ -9,12 +9,12 @@ import { parseArgs } from "util"; import { createWalletClient, http, publicActions } from "viem"; import { privateKeyToAccount } from "viem/accounts"; -import { foundry } from "viem/chains"; import { existsSync, readFileSync } from "fs"; import { resolve, dirname, join } from "path"; import { fileURLToPath } from "url"; import { makeClient } from "alkahest-ts"; import { makeLLMClient } from "../.."; +import { getChainFromNetwork } from "../utils.js"; // Get the directory of the current module const __filename = fileURLToPath(import.meta.url); @@ -160,19 +160,21 @@ async function main() { const deployment = JSON.parse(readFileSync(resolvedDeploymentPath, "utf-8")); const rpcUrl = args["rpc-url"] || deployment.rpcUrl; + const chain = getChainFromNetwork(deployment.network); console.log("🚀 Fulfilling Natural Language Agreement Escrow\n"); console.log("Configuration:"); console.log(` 📦 Escrow UID: ${escrowUid}`); console.log(` 📝 Fulfillment: "${fulfillment}"`); console.log(` ⚖️ Oracle: ${oracleAddress}`); + console.log(` 🌐 Network: ${deployment.network}`); console.log(` 🌐 RPC URL: ${rpcUrl}\n`); // Create account and wallet const account = privateKeyToAccount(privateKey as `0x${string}`); const walletClient = createWalletClient({ account, - chain: foundry, + chain, transport: http(rpcUrl), }).extend(publicActions); diff --git a/cli/utils.ts b/cli/utils.ts new file mode 100644 index 0000000..0a96f36 --- /dev/null +++ b/cli/utils.ts @@ -0,0 +1,23 @@ +/** + * Shared utilities for NLA CLI + */ + +import { foundry, sepolia, mainnet } from "viem/chains"; +import type { Chain } from "viem/chains"; + +/** + * Get viem chain configuration from network name + */ +export function getChainFromNetwork(network: string): Chain { + switch (network.toLowerCase()) { + case "localhost": + case "devnet": + return foundry; + case "sepolia": + return sepolia; + case "mainnet": + return mainnet; + default: + return foundry; + } +}