// index.js
import { Client, PrivateKey } from '@hiero-ledger/sdk';
import { AgentMode } from '@hashgraph/hedera-agent-kit';
import { allCorePlugins } from '@hashgraph/hedera-agent-kit/plugins';
import { HederaLangchainToolkit } from '@hashgraph/hedera-agent-kit-langchain';
import { createAgent } from 'langchain';
import { ChatOpenAI } from '@langchain/openai';
import 'dotenv/config';
const client = Client.forTestnet().setOperator(
process.env.ACCOUNT_ID,
PrivateKey.fromStringECDSA(process.env.PRIVATE_KEY),
// PrivateKey.fromStringED25519(process.env.PRIVATE_KEY), // use this instead for ED25519 keys
);
const toolkit = new HederaLangchainToolkit({
client,
configuration: {
tools: [],
plugins: allCorePlugins,
context: { mode: AgentMode.AUTONOMOUS },
},
});
const agent = createAgent({
model: new ChatOpenAI({ model: 'gpt-4o-mini' }),
tools: toolkit.getTools(),
systemPrompt: 'You are a helpful assistant with access to Hedera blockchain tools.',
});
const response = await agent.invoke({
messages: [{ role: 'user', content: "what's my balance?" }],
});
console.log(response.messages[response.messages.length - 1].content);