zetachain-langchain-tools
v1.1.0
Published
LangChain tools for ZetaChain CLI MCP server
Maintainers
Readme
ZetaChain LangChain Tools
LangChain tools for interacting with ZetaChain's cross-chain infrastructure via the MCP server.
Installation
npm install zetachain-langchain-toolsQuick Start
With Anthropic Claude (Recommended)
import { ChatAnthropic } from "@langchain/anthropic";
import { createZetaChainTools } from 'zetachain-langchain-tools';
import { AgentExecutor, createToolCallingAgent } from "langchain/agents";
import { ChatPromptTemplate, MessagesPlaceholder } from "@langchain/core/prompts";
// Initialize Claude model
const model = new ChatAnthropic({
modelName: "claude-3-5-sonnet-20241022",
temperature: 0.1,
// Uses ANTHROPIC_API_KEY from environment
});
// Create ZetaChain tools
const tools = createZetaChainTools({
apiKey: process.env.ZETACHAIN_API_KEY!
});
// Create prompt template
const prompt = ChatPromptTemplate.fromMessages([
["system", "You are a helpful blockchain assistant with access to ZetaChain cross-chain tools."],
["human", "{input}"],
new MessagesPlaceholder("agent_scratchpad"),
]);
// Create agent
const agent = await createToolCallingAgent({
llm: model,
tools,
prompt,
});
const agentExecutor = new AgentExecutor({
agent,
tools,
});
// Use the agent
const result = await agentExecutor.invoke({
input: "Check ETH balance for 0x742d35Cc6C7486B4E1f5312b2E6a9F9E2A91D1b0"
});With OpenAI (Alternative)
import { createZetaChainTools } from 'zetachain-langchain-tools';
import { AgentExecutor, createOpenAIFunctionsAgent } from "langchain/agents";
import { ChatOpenAI } from "@langchain/openai";
const tools = createZetaChainTools({
apiKey: process.env.ZETACHAIN_API_KEY!
});
const llm = new ChatOpenAI({ modelName: "gpt-4" });
// Create agent with ZetaChain tools
const agent = await createOpenAIFunctionsAgent({
llm,
tools,
prompt: /* your prompt */,
});
const agentExecutor = new AgentExecutor({
agent,
tools,
});
// Use the agent
const result = await agentExecutor.invoke({
input: "Check my account balances on Ethereum and Polygon"
});Available Tools
zetachain_get_balances- Get balances across multiple networkszetachain_list_accounts- List managed accountszetachain_send_transaction- Send cross-chain transactionszetachain_create_account- Create new blockchain accountszetachain_get_network_info- Get network informationzetachain_estimate_gas- Estimate gas fees
Configuration
Set your ZetaChain API key:
export ZETACHAIN_API_KEY=your_api_key_hereExamples
Check Balances
await agentExecutor.invoke({
input: "What's the ETH balance for 0x742d35Cc6C7486B4E1f5312b2E6a9F9E2A91D1b0?"
});Send Cross-Chain Transaction
await agentExecutor.invoke({
input: "Send 0.1 ETH from my Ethereum account to my Polygon account"
});Create New Account
await agentExecutor.invoke({
input: "Create a new Solana account named 'trading-wallet'"
});