diff --git a/.gitignore b/.gitignore index 1d6a65c465..a82e47b2b1 100644 --- a/.gitignore +++ b/.gitignore @@ -53,6 +53,7 @@ tsup.config.bundled_*.mjs .cursorrules .pnpm-store instructions.md +wallet_data.txt coverage .eslintcache diff --git a/packages/plugin-agentkit/src/provider.ts b/packages/plugin-agentkit/src/provider.ts index 8336fd5f0a..b7a92e6831 100644 --- a/packages/plugin-agentkit/src/provider.ts +++ b/packages/plugin-agentkit/src/provider.ts @@ -1,11 +1,34 @@ import { type Provider, type IAgentRuntime } from "@elizaos/core"; import { CdpAgentkit } from "@coinbase/cdp-agentkit-core"; +import * as fs from "fs"; + +const WALLET_DATA_FILE = "wallet_data.txt"; export async function getClient(): Promise { + let walletDataStr: string | null = null; + + // Read existing wallet data if available + if (fs.existsSync(WALLET_DATA_FILE)) { + try { + walletDataStr = fs.readFileSync(WALLET_DATA_FILE, "utf8"); + } catch (error) { + console.error("Error reading wallet data:", error); + // Continue without wallet data + } + } + + // Configure CDP AgentKit const config = { + cdpWalletData: walletDataStr || undefined, networkId: "base-sepolia", }; - return await CdpAgentkit.configureWithWallet(config); + + const agentkit = await CdpAgentkit.configureWithWallet(config); + // Save wallet data + const exportedWallet = await agentkit.exportWallet(); + fs.writeFileSync(WALLET_DATA_FILE, exportedWallet); + + return agentkit; } export const walletProvider: Provider = {