125 lines
2.8 KiB
Plaintext
Executable File

---
title: 'Quickstart Guide'
description: 'Get started with Solana Agent Kit in minutes'
---
This guide will help you get up and running with Solana Agent Kit quickly.
## Installation
```bash
pnpm install solana-agent-kit
```
## Setup
1. Create a `.env` file in your project root:
```env
OPENAI_API_KEY=your_openai_api_key
RPC_URL=your_rpc_url
SOLANA_PRIVATE_KEY=your_private_key
```
1. Create a new file (e.g., `agent.ts`) and initialize the agent:
```typescript
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,
});
}
```
## Interactive Mode
Create a chat interface to interact with your agent:
```typescript
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);
```
## Example Commands
Once your agent is running, you can interact with it using natural language:
```
"Create a new token with 1000000 supply"
"Check my wallet balance"
"Mint an NFT named 'My Cool NFT'"
"Swap 1 SOL for USDC"
```
## Available Features
Your agent can perform various operations:
* ๐Ÿช™ Create and manage tokens
* ๐ŸŽจ Mint NFTs and deploy collections
* ๐Ÿ’ฑ Swap tokens using Jupiter
* ๐Ÿ’ฐ Check balances and transfer assets
* ๐ŸŽฎ Execute Solana Programs
* ๐Ÿ“ฆ Send compressed airdrops
## Troubleshooting
If you encounter issues:
1. Ensure all environment variables are set correctly
2. Verify your RPC endpoint is responsive
3. Check that your wallet has sufficient SOL for transactions
4. For API errors, try again with increased priority fees