A template for building autonomous AI agents that can interact with Starknet blockchain using LangChain and a Telegram bot interface.
This template provides the foundation for creating AI agents that can:
- Execute transactions on Starknet (ETH and ERC20 transfers)
- Interact with DeFi protocols (token swaps)
- Monitor blockchain activity and news
- Manage wallets automatically
- Run background tasks
- Interface through Telegram
The template is built with LangChain's state management and tool system, making it easy to extend with custom capabilities.
- Agent System: Built on LangChain's StateGraph for complex conversation flows
- Tool System: Modular architecture for blockchain interactions
- Wallet Management: Automated account creation and deployment
- Storage System: Encrypted persistent storage for sensitive data
- Telegram Interface: Ready-to-use bot setup for user interactions
-
Clone the template:
git clone <repository-url> npm install
-
Configure environment variables in
.env
:OPENAI_API_KEY=your_openai_api_key RPC_URL=your_starknet_rpc_url BOT_TOKEN=your_telegram_bot_token STORAGE_ENCRYPTION_KEY=your_encryption_key STARKNET_ACCOUNT_ADDRESS=your_account_address #optional STARKNET_PRIVATE_KEY=your_private_key #optional
-
Customize the agent:
- Add new tools in
tools/
directory - Modify conversation flows in
agent.ts
- Extend background tasks as needed
- Add custom storage handlers
- Add new tools in
-
Start the agent:
npm start
or to use cli interface instead of Telegram:
npm dev
-
Try asking it the following:
- "What is my account token balance?"
- "Send ETH to a random Starknet account"
- "Swap ETH to STRK"
- "Check the news every few hours and decide if it is a good time to swap my tokens and do it"
Create new tools in tools/
following the existing pattern:
import { tool } from "@langchain/core/tools";
import { z } from "zod";
export const myNewTool = tool(
async ({ param1, param2 }, options) => {
// Tool implementation
},
{
name: "my_new_tool",
description: "Description of what the tool does",
schema: z.object({
param1: z.string().describe("Description of param1"),
param2: z.number().describe("Description of param2"),
}),
}
);
Then add it to tools/index.ts
and register in agent.ts
.
├── tools/
│ ├── account/ # Account management tools
│ ├── monitoring/ # Blockchain monitoring tools
│ ├── token/ # Token interaction tools
│ └── transactions/ # Transaction execution tools
├── util/ # Utility functions
├── agent.ts # Main agent logic
└── constants.ts # Configuration constants
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Submit a pull request