This guide demonstrates how to integrate and use Solana Agent Kit v2 Beta in your applications, showcasing a modular, plugin-based architecture for building Solana-powered applications and AI agents.
import { SolanaAgentKit, KeypairWallet } from "solana-agent-kit";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";import * as dotenv from "dotenv";import { Keypair } from "@solana/web3.js";import bs58 from "bs58";dotenv.config();// Initialize wallet// We are using Keypair for this demo, but it can be connected to Embedded walletconst keyPair = Keypair.fromSecretKey( bs58.decode(process.env.SOLANA_PRIVATE_KEY as string));const wallet = new KeypairWallet(keyPair, process.env.RPC_URL as string);// Initialize agent with wallet and RPC URL, then add pluginsconst 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);
Solana Agent Kit v2 provides built-in integration with Vercel AI SDK:
Copy
import { createVercelAITools } from "solana-agent-kit";import { createAI } from "ai";// Create AI tools from agent's actionsconst tools = createVercelAITools(agent, agent.actions);// Create AI configurationconst ai = createAI({ actions: tools, initialMessages: [ { role: "system", content: "You are a helpful agent that can interact with Solana blockchain." } ]});