Get started with Solana Agent Kit in minutes
pnpm install solana-agent-kit
.env
OPENAI_API_KEY=your_openai_api_key RPC_URL=your_rpc_url SOLANA_PRIVATE_KEY=your_private_key
agent.ts
import { SolanaAgentKit, createSolanaTools } from "solana-agent-kit"; import { HumanMessage } from "@langchain/core/messages"; import { ChatOpenAI } from "@langchain/openai"; import { createReactAgent } from "@langchain/langgraph/prebuilt"; import { MemorySaver } from "@langchain/langgraph"; import * as dotenv from "dotenv"; dotenv.config(); async function initializeAgent() { const llm = new ChatOpenAI({ modelName: "gpt-4", temperature: 0.7, }); const solanaKit = new SolanaAgentKit( process.env.SOLANA_PRIVATE_KEY!, process.env.RPC_URL, process.env.OPENAI_API_KEY! ); const tools = createSolanaTools(solanaKit); const memory = new MemorySaver(); const config = { configurable: { thread_id: "Solana Agent Kit!" } }; return createReactAgent({ llm, tools, checkpointSaver: memory, }); }
async function runChat() { const agent = await initializeAgent(); const config = { configurable: { thread_id: "Solana Agent Kit!" } }; // Example: Send a command to the agent const stream = await agent.stream({ messages: [new HumanMessage("Create a new token with 1000000 supply")] }, config); // Handle the response for await (const chunk of stream) { if ("agent" in chunk) { console.log(chunk.agent.messages[0].content); } else if ("tools" in chunk) { console.log(chunk.tools.messages[0].content); } console.log("-------------------"); } } runChat().catch(console.error);
"Create a new token with 1000000 supply" "Check my wallet balance" "Mint an NFT named 'My Cool NFT'" "Swap 1 SOL for USDC"
Was this page helpful?