fix: update client chain base on network

This commit is contained in:
ngoc 2026-01-26 12:07:46 +07:00
parent 64420df6dd
commit c0b8179d6c
No known key found for this signature in database
GPG Key ID: 51FE6110113A5C32
4 changed files with 34 additions and 6 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);

23
cli/utils.ts Normal file
View File

@ -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;
}
}