Skip to content

Commit

Permalink
I load existing wallet data for provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
sweetmantech committed Jan 15, 2025
1 parent 587c1df commit 6c6d0a4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ tsup.config.bundled_*.mjs
.cursorrules
.pnpm-store
instructions.md
wallet_data.txt

coverage
.eslintcache
Expand Down
25 changes: 24 additions & 1 deletion packages/plugin-agentkit/src/provider.ts
Original file line number Diff line number Diff line change
@@ -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<CdpAgentkit> {
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 = {
Expand Down

0 comments on commit 6c6d0a4

Please sign in to comment.