Loading...
Loading...
Compare original and translation side by side
| Feature | Description |
|---|---|
| 60+ Actions | Token, NFT, DeFi, staking, bridging operations |
| Plugin Architecture | Modular - use only what you need |
| Multi-Framework | LangChain, Vercel AI SDK, MCP, Eliza |
| Model Agnostic | Works with OpenAI, Claude, Llama, Gemini |
| Autonomous Mode | Hands-off execution with error recovery |
| 特性 | 描述 |
|---|---|
| 60+操作 | 代币、NFT、DeFi、质押、跨链桥接等各类操作 |
| 插件架构 | 模块化设计 - 仅加载所需功能 |
| 多框架支持 | 兼容LangChain、Vercel AI SDK、MCP、Eliza |
| 模型无关 | 支持OpenAI、Claude、Llama、Gemini等模型 |
| 自主模式 | 无需人工干预的执行流程,附带错误恢复机制 |
undefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedimport {
SolanaAgentKit,
createVercelAITools,
KeypairWallet,
} from "solana-agent-kit";
import { Keypair } from "@solana/web3.js";
import bs58 from "bs58";
// Import plugins
import TokenPlugin from "@solana-agent-kit/plugin-token";
import NFTPlugin from "@solana-agent-kit/plugin-nft";
import DefiPlugin from "@solana-agent-kit/plugin-defi";
import MiscPlugin from "@solana-agent-kit/plugin-misc";
import BlinksPlugin from "@solana-agent-kit/plugin-blinks";
// Create wallet from private key
const privateKey = bs58.decode(process.env.SOLANA_PRIVATE_KEY!);
const keypair = Keypair.fromSecretKey(privateKey);
const wallet = new KeypairWallet(keypair);
// Initialize agent with plugins
const agent = new SolanaAgentKit(
wallet,
process.env.RPC_URL!,
{
OPENAI_API_KEY: process.env.OPENAI_API_KEY!,
}
)
.use(TokenPlugin)
.use(NFTPlugin)
.use(DefiPlugin)
.use(MiscPlugin)
.use(BlinksPlugin);
// Create tools for AI framework
const tools = createVercelAITools(agent, agent.actions);import {
SolanaAgentKit,
createVercelAITools,
KeypairWallet,
} from "solana-agent-kit";
import { Keypair } from "@solana/web3.js";
import bs58 from "bs58";
// 导入插件
import TokenPlugin from "@solana-agent-kit/plugin-token";
import NFTPlugin from "@solana-agent-kit/plugin-nft";
import DefiPlugin from "@solana-agent-kit/plugin-defi";
import MiscPlugin from "@solana-agent-kit/plugin-misc";
import BlinksPlugin from "@solana-agent-kit/plugin-blinks";
// 从私钥创建钱包
const privateKey = bs58.decode(process.env.SOLANA_PRIVATE_KEY!);
const keypair = Keypair.fromSecretKey(privateKey);
const wallet = new KeypairWallet(keypair);
// 初始化Agent并加载插件
const agent = new SolanaAgentKit(
wallet,
process.env.RPC_URL!,
{
OPENAI_API_KEY: process.env.OPENAI_API_KEY!,
}
)
.use(TokenPlugin)
.use(NFTPlugin)
.use(DefiPlugin)
.use(MiscPlugin)
.use(BlinksPlugin);
// 为AI框架创建工具
const tools = createVercelAITools(agent, agent.actions);@solana-agent-kit/plugin-token@solana-agent-kit/plugin-token| Action | Description |
|---|---|
| Deploy new SPL token or Token-2022 |
| Transfer SOL or SPL tokens |
| Check token balances |
| Stake SOL via Jupiter/Solayer |
| Bridge tokens via Wormhole |
| Analyze token safety |
// Deploy a new token
const result = await agent.methods.deployToken({
name: "My Token",
symbol: "MTK",
decimals: 9,
initialSupply: 1000000,
});
// Transfer tokens
await agent.methods.transfer({
to: "recipient_address",
amount: 100,
mint: "token_mint_address", // optional, defaults to SOL
});
// Check balance
const balance = await agent.methods.getBalance({
tokenAddress: "token_mint_address", // optional
});| 操作 | 描述 |
|---|---|
| 部署新的SPL代币或Token-2022代币 |
| 转账SOL或SPL代币 |
| 查询代币余额 |
| 通过Jupiter/Solayer质押SOL |
| 通过Wormhole跨链桥接代币 |
| 分析代币安全性 |
// 部署新代币
const result = await agent.methods.deployToken({
name: "My Token",
symbol: "MTK",
decimals: 9,
initialSupply: 1000000,
});
// 转账代币
await agent.methods.transfer({
to: "recipient_address",
amount: 100,
mint: "token_mint_address", // 可选,默认是SOL
});
// 查询余额
const balance = await agent.methods.getBalance({
tokenAddress: "token_mint_address", // 可选
});@solana-agent-kit/plugin-nft@solana-agent-kit/plugin-nft| Action | Description |
|---|---|
| Create NFT collection via Metaplex |
| Mint NFT to collection |
| List NFT on marketplaces |
| Update NFT metadata |
// Create collection
const collection = await agent.methods.createCollection({
name: "My Collection",
symbol: "MYCOL",
uri: "https://arweave.net/metadata.json",
});
// Mint NFT to collection
const nft = await agent.methods.mintNFT({
collectionMint: collection.collectionAddress,
name: "NFT #1",
uri: "https://arweave.net/nft1.json",
});| 操作 | 描述 |
|---|---|
| 通过Metaplex创建NFT合集 |
| 向合集中铸造NFT |
| 在NFT市场上架NFT |
| 更新NFT元数据 |
// 创建合集
const collection = await agent.methods.createCollection({
name: "My Collection",
symbol: "MYCOL",
uri: "https://arweave.net/metadata.json",
});
// 向合集中铸造NFT
const nft = await agent.methods.mintNFT({
collectionMint: collection.collectionAddress,
name: "NFT #1",
uri: "https://arweave.net/nft1.json",
});@solana-agent-kit/plugin-defi@solana-agent-kit/plugin-defi| Action | Description |
|---|---|
| Swap tokens via Jupiter |
| Create Raydium AMM pool |
| Create Orca Whirlpool |
| Create Meteora DLMM pool |
| Place limit order via Manifest |
| Lend assets via Lulo |
| Trade perps via Adrena/Drift |
// Swap tokens via Jupiter
const swap = await agent.methods.trade({
outputMint: "target_token_mint",
inputAmount: 1.0,
inputMint: "So11111111111111111111111111111111111111112", // SOL
slippageBps: 50, // 0.5%
});
// Create Raydium CPMM pool
const pool = await agent.methods.createRaydiumCpmm({
mintA: "token_a_mint",
mintB: "token_b_mint",
configId: "config_id",
mintAAmount: 1000,
mintBAmount: 1000,
});| 操作 | 描述 |
|---|---|
| 通过Jupiter交换代币 |
| 创建Raydium AMM池 |
| 创建Orca Whirlpool |
| 创建Meteora DLMM池 |
| 通过Manifest挂限价单 |
| 通过Lulo出借资产 |
| 通过Adrena/Drift交易永续合约 |
// 通过Jupiter交换代币
const swap = await agent.methods.trade({
outputMint: "target_token_mint",
inputAmount: 1.0,
inputMint: "So11111111111111111111111111111111111111112", // SOL
slippageBps: 50, // 0.5%
});
// 创建Raydium CPMM池
const pool = await agent.methods.createRaydiumCpmm({
mintA: "token_a_mint",
mintB: "token_b_mint",
configId: "config_id",
mintAAmount: 1000,
mintBAmount: 1000,
});@solana-agent-kit/plugin-misc@solana-agent-kit/plugin-misc| Action | Description |
|---|---|
| ZK-compressed airdrop via Helius |
| Get token price via CoinGecko |
| Register .sol domain |
| Resolve domain to address |
| Get network TPS |
// Compressed airdrop (cost-efficient)
const airdrop = await agent.methods.sendCompressedAirdrop({
mintAddress: "token_mint",
amount: 100,
recipients: ["addr1", "addr2", "addr3"],
priorityFeeInLamports: 10000,
});
// Get token price
const price = await agent.methods.getPrice({
tokenId: "solana", // CoinGecko ID
});| 操作 | 描述 |
|---|---|
| 通过Helius实现ZK压缩空投 |
| 通过CoinGecko获取代币价格 |
| 注册.sol域名 |
| 将域名解析为地址 |
| 获取网络TPS |
// 压缩空投(成本更低)
const airdrop = await agent.methods.sendCompressedAirdrop({
mintAddress: "token_mint",
amount: 100,
recipients: ["addr1", "addr2", "addr3"],
priorityFeeInLamports: 10000,
});
// 获取代币价格
const price = await agent.methods.getPrice({
tokenId: "solana", // CoinGecko ID
});@solana-agent-kit/plugin-blinks@solana-agent-kit/plugin-blinks// Execute a Blink
const result = await agent.methods.executeBlink({
blinkUrl: "https://example.com/blink",
params: { /* blink-specific params */ },
});// 执行Blink
const result = await agent.methods.executeBlink({
blinkUrl: "https://example.com/blink",
params: { /* blink专属参数 */ },
});import { SolanaAgentKit, createSolanaTools } from "solana-agent-kit";
import { ChatOpenAI } from "@langchain/openai";
import { createReactAgent } from "@langchain/langgraph/prebuilt";
import { MemorySaver } from "@langchain/langgraph";
import { HumanMessage } from "@langchain/core/messages";
async function createLangChainAgent() {
// Initialize LLM
const llm = new ChatOpenAI({
modelName: "gpt-4-turbo-preview",
temperature: 0.7,
});
// Initialize Solana Agent Kit
const solanaKit = new SolanaAgentKit(
wallet,
process.env.RPC_URL!,
{ OPENAI_API_KEY: process.env.OPENAI_API_KEY! }
)
.use(TokenPlugin)
.use(DefiPlugin);
// Create LangChain tools
const tools = createSolanaTools(solanaKit);
// Create agent with memory
const memory = new MemorySaver();
const agent = createReactAgent({
llm,
tools,
checkpointSaver: memory,
});
return agent;
}
// Run agent
async function chat(agent: any, message: string) {
const config = { configurable: { thread_id: "solana-agent" } };
const stream = await agent.stream(
{ messages: [new HumanMessage(message)] },
config
);
for await (const chunk of stream) {
if ("agent" in chunk) {
console.log(chunk.agent.messages[0].content);
}
}
}import { SolanaAgentKit, createSolanaTools } from "solana-agent-kit";
import { ChatOpenAI } from "@langchain/openai";
import { createReactAgent } from "@langchain/langgraph/prebuilt";
import { MemorySaver } from "@langchain/langgraph";
import { HumanMessage } from "@langchain/core/messages";
async function createLangChainAgent() {
// 初始化大语言模型
const llm = new ChatOpenAI({
modelName: "gpt-4-turbo-preview",
temperature: 0.7,
});
// 初始化Solana Agent Kit
const solanaKit = new SolanaAgentKit(
wallet,
process.env.RPC_URL!,
{ OPENAI_API_KEY: process.env.OPENAI_API_KEY! }
)
.use(TokenPlugin)
.use(DefiPlugin);
// 创建LangChain工具
const tools = createSolanaTools(solanaKit);
// 创建带记忆功能的Agent
const memory = new MemorySaver();
const agent = createReactAgent({
llm,
tools,
checkpointSaver: memory,
});
return agent;
}
// 运行Agent
async function chat(agent: any, message: string) {
const config = { configurable: { thread_id: "solana-agent" } };
const stream = await agent.stream(
{ messages: [new HumanMessage(message)] },
config
);
for await (const chunk of stream) {
if ("agent" in chunk) {
console.log(chunk.agent.messages[0].content);
}
}
}import { SolanaAgentKit, createVercelAITools } from "solana-agent-kit";
import { openai } from "@ai-sdk/openai";
import { generateText } from "ai";
async function runVercelAgent(prompt: string) {
const agent = new SolanaAgentKit(wallet, rpcUrl, options)
.use(TokenPlugin)
.use(DefiPlugin);
const tools = createVercelAITools(agent, agent.actions);
const result = await generateText({
model: openai("gpt-4-turbo"),
tools,
maxSteps: 10,
prompt,
});
return result.text;
}
// Usage
const response = await runVercelAgent(
"Swap 0.1 SOL for USDC using the best rate"
);import { SolanaAgentKit, createVercelAITools } from "solana-agent-kit";
import { openai } from "@ai-sdk/openai";
import { generateText } from "ai";
async function runVercelAgent(prompt: string) {
const agent = new SolanaAgentKit(wallet, rpcUrl, options)
.use(TokenPlugin)
.use(DefiPlugin);
const tools = createVercelAITools(agent, agent.actions);
const result = await generateText({
model: openai("gpt-4-turbo"),
tools,
maxSteps: 10,
prompt,
});
return result.text;
}
// 使用示例
const response = await runVercelAgent(
"用最优汇率将0.1 SOL兑换为USDC"
);undefinedundefined
Add to Claude Desktop config (`~/Library/Application Support/Claude/claude_desktop_config.json`):
```json
{
"mcpServers": {
"solana": {
"command": "npx",
"args": ["solana-mcp"],
"env": {
"RPC_URL": "https://api.mainnet-beta.solana.com",
"SOLANA_PRIVATE_KEY": "your_base58_private_key",
"OPENAI_API_KEY": "your_openai_key"
}
}
}
}GET_ASSETDEPLOY_TOKENGET_PRICEWALLET_ADDRESSBALANCETRANSFERMINT_NFTTRADEREQUEST_FUNDSRESOLVE_DOMAINGET_TPS
添加到Claude Desktop配置文件(`~/Library/Application Support/Claude/claude_desktop_config.json`):
```json
{
"mcpServers": {
"solana": {
"command": "npx",
"args": ["solana-mcp"],
"env": {
"RPC_URL": "https://api.mainnet-beta.solana.com",
"SOLANA_PRIVATE_KEY": "your_base58_private_key",
"OPENAI_API_KEY": "your_openai_key"
}
}
}
}GET_ASSETDEPLOY_TOKENGET_PRICEWALLET_ADDRESSBALANCETRANSFERMINT_NFTTRADEREQUEST_FUNDSRESOLVE_DOMAINGET_TPSimport { SolanaAgentKit } from "solana-agent-kit";
const agent = new SolanaAgentKit(wallet, rpcUrl, options)
.use(TokenPlugin)
.use(DefiPlugin);
// Configure autonomous behavior
const autonomousConfig = {
intervalMs: 60000, // Check every minute
maxActions: 100, // Max actions per session
errorRecovery: true, // Auto-retry on failures
dryRun: false, // Set true for testing
};
// Start autonomous loop
async function runAutonomous() {
while (true) {
try {
// Agent decides what to do based on market conditions
const decision = await agent.analyze({
context: "Monitor my portfolio and rebalance if needed",
constraints: [
"Keep at least 1 SOL for gas",
"Max 10% allocation per token",
],
});
if (decision.shouldAct) {
await agent.execute(decision.action);
}
await sleep(autonomousConfig.intervalMs);
} catch (error) {
if (autonomousConfig.errorRecovery) {
console.error("Error, recovering:", error);
await sleep(5000);
} else {
throw error;
}
}
}
}import { SolanaAgentKit } from "solana-agent-kit";
const agent = new SolanaAgentKit(wallet, rpcUrl, options)
.use(TokenPlugin)
.use(DefiPlugin);
// 配置自主行为
const autonomousConfig = {
intervalMs: 60000, // 每分钟检查一次
maxActions: 100, // 每次会话最多执行100个操作
errorRecovery: true, // 失败时自动重试
dryRun: false, // 测试时设为true
};
// 启动自主循环
async function runAutonomous() {
while (true) {
try {
// Agent根据市场状况决定执行操作
const decision = await agent.analyze({
context: "监控我的投资组合,必要时进行再平衡",
constraints: [
"保留至少1 SOL作为手续费",
"单一代币最大配置比例不超过10%",
],
});
if (decision.shouldAct) {
await agent.execute(decision.action);
}
await sleep(autonomousConfig.intervalMs);
} catch (error) {
if (autonomousConfig.errorRecovery) {
console.error("发生错误,正在恢复:", error);
await sleep(5000);
} else {
throw error;
}
}
}
}import { Action, Tool, SolanaAgentKit } from "solana-agent-kit";
// Define the Tool (tells LLM HOW to use it)
const myCustomTool: Tool = {
name: "my_custom_action",
description: "Does something custom on Solana",
parameters: {
type: "object",
properties: {
param1: {
type: "string",
description: "First parameter",
},
param2: {
type: "number",
description: "Second parameter",
},
},
required: ["param1"],
},
};
// Define the Action (tells agent WHEN and WHY to use it)
const myCustomAction: Action = {
name: "my_custom_action",
description: "Use this when you need to do something custom",
similes: ["custom thing", "special operation"],
examples: [
{
input: "Do the custom thing with value X",
output: "Custom action executed with param1=X",
},
],
handler: async (agent: SolanaAgentKit, params: any) => {
const { param1, param2 } = params;
// Your custom logic here
const connection = agent.connection;
const wallet = agent.wallet;
// Execute Solana operations...
return {
success: true,
result: `Executed with ${param1}`,
};
},
};
// Register custom action
agent.registerAction(myCustomAction);
agent.registerTool(myCustomTool);import { Action, Tool, SolanaAgentKit } from "solana-agent-kit";
// 定义工具(告诉大语言模型如何使用)
const myCustomTool: Tool = {
name: "my_custom_action",
description: "在Solana上执行自定义操作",
parameters: {
type: "object",
properties: {
param1: {
type: "string",
description: "第一个参数",
},
param2: {
type: "number",
description: "第二个参数",
},
},
required: ["param1"],
},
};
// 定义操作(告诉Agent何时及为何使用)
const myCustomAction: Action = {
name: "my_custom_action",
description: "当你需要执行自定义操作时使用",
similes: ["custom thing", "special operation"],
examples: [
{
input: "用值X执行自定义操作",
output: "已执行自定义操作,param1=X",
},
],
handler: async (agent: SolanaAgentKit, params: any) => {
const { param1, param2 } = params;
// 你的自定义逻辑
const connection = agent.connection;
const wallet = agent.wallet;
// 执行Solana操作...
return {
success: true,
result: `已执行,参数为${param1}`,
};
},
};
// 注册自定义操作
agent.registerAction(myCustomAction);
agent.registerTool(myCustomTool);solana-agent-kit/
├── SKILL.md # This file
├── resources/
│ ├── actions-reference.md # Complete actions list
│ ├── plugins-guide.md # Plugin deep dive
│ └── security-checklist.md # Security best practices
├── examples/
│ ├── langchain/ # LangChain integration
│ ├── vercel-ai/ # Vercel AI SDK
│ ├── mcp-server/ # Claude MCP setup
│ └── autonomous-agent/ # Autonomous patterns
├── templates/
│ └── agent-template.ts # Starter template
└── docs/
├── custom-actions.md # Creating custom actions
└── troubleshooting.md # Common issuessolana-agent-kit/
├── SKILL.md # 本文档
├── resources/
│ ├── actions-reference.md # 完整操作列表
│ ├── plugins-guide.md # 插件深度指南
│ └── security-checklist.md # 安全最佳实践
├── examples/
│ ├── langchain/ # LangChain集成示例
│ ├── vercel-ai/ # Vercel AI SDK示例
│ ├── mcp-server/ # Claude MCP配置示例
│ └── autonomous-agent/ # 自主Agent模式示例
├── templates/
│ └── agent-template.ts # 入门模板
└── docs/
├── custom-actions.md # 创建自定义操作指南
└── troubleshooting.md # 常见问题排查import { TurnkeyWallet, PrivyWallet } from "solana-agent-kit/wallets";
// Turnkey - fine-grained rules and policies
const turnkeyWallet = new TurnkeyWallet({
organizationId: process.env.TURNKEY_ORG_ID,
privateKeyId: process.env.TURNKEY_PRIVATE_KEY_ID,
});
// Privy - human-in-the-loop confirmation
const privyWallet = new PrivyWallet({
appId: process.env.PRIVY_APP_ID,
requireConfirmation: true,
});
// Initialize agent with secure wallet
const agent = new SolanaAgentKit(turnkeyWallet, rpcUrl, options)
.use(TokenPlugin)
.use(DefiPlugin);import { TurnkeyWallet, PrivyWallet } from "solana-agent-kit/wallets";
// Turnkey - 细粒度规则和策略
const turnkeyWallet = new TurnkeyWallet({
organizationId: process.env.TURNKEY_ORG_ID,
privateKeyId: process.env.TURNKEY_PRIVATE_KEY_ID,
});
// Privy - 人工确认机制
const privyWallet = new PrivyWallet({
appId: process.env.PRIVY_APP_ID,
requireConfirmation: true,
});
// 使用安全钱包初始化Agent
const agent = new SolanaAgentKit(turnkeyWallet, rpcUrl, options)
.use(TokenPlugin)
.use(DefiPlugin);| Feature | V1 | V2 |
|---|---|---|
| Wallet Security | Private key input | Embedded wallets (Turnkey, Privy) |
| Tool Loading | All 100+ tools | Plugin-based, load what you need |
| LLM Context | Large, caused hallucinations | Minimal, focused context |
| Human-in-loop | Not supported | Native with Privy |
| 特性 | V1 | V2 |
|---|---|---|
| 钱包安全性 | 输入私钥 | 嵌入式钱包(Turnkey、Privy) |
| 工具加载 | 全部100+工具 | 基于插件,仅加载所需 |
| 大语言模型上下文 | 庞大,易导致幻觉 | 精简,聚焦核心 |
| 人工介入机制 | 不支持 | 原生支持Privy |
solana-agent-kit-pysolana-agent-kit-py