How to Build Solana AI Agents in 2026
Author: Alchemy

AI agents are transforming how we interact with blockchain infrastructure. These autonomous programs can execute transactions, manage portfolios, mint NFTs, and interact with DeFi protocols, all through natural language commands. A far cry from crypto’s early UX.
Solana has emerged as the leading blockchain for AI agent development, accounting for 77% of x402 transaction volume in December 2025 combining sub-second finality, negligible transaction costs, and a mature ecosystem of frameworks purpose-built for agentic applications.
This guide walks through building production-ready AI agents on Solana, from choosing the right framework to implementing secure wallet architectures. Whether you're building a trading bot, a personal onchain assistant, or an autonomous DeFi manager, you'll find the technical foundation you need here.
Why Solana for AI Agents?
AI agents have the potential to transform onchain activity and unlock entirely new use cases, leading to a major question for developers who want to get started is: which blockchain do you build AI agents on?
The answer, increasingly, is Solana. A single agent monitoring markets, executing trades, and rebalancing portfolios might submit hundreds of transactions daily. On Ethereum mainnet, that operational tempo could cost thousands of dollars in gas. On Solana, it's pennies. But cost is just the starting point, Solana's architecture aligns with agent requirements in ways that go far deeper than fees:
Speed matters for autonomy: Agents need to react to market conditions, user requests, and onchain events in real time. Solana's 400ms block times and sub second finality enables tight feedback loops. Agents operate in cycles: reason about what to do, execute an action, observe the result, then reason again. Each "observe" step requires waiting for transaction confirmation. On a 12-second block time chain, a 3-step workflow means 36+ seconds of idle waiting between decisions, the agent loses the tight feedback loop that makes autonomous operation feel responsive. On Solana, that same workflow confirms in under 2 seconds, letting agents reason and act in near real-time. This is the difference between an agent that feels like a batch job you submitted and one that feels like a collaborator working alongside you.
Predictable fees enable planning: Agents need to budget for operations. Solana's fee model, roughly $0.00025 per transaction, lets developers build agents that can operate indefinitely on minimal capital. Priority fees during congestion remain reasonable compared to gas auctions found on other chains.
Native program composability: Solana programs can call other programs atomically within a single transaction. An agent can swap tokens on Jupiter, stake the output on Marinade, and mint a receipt NFT, all in one atomic operation. This composability is what separates Solana agents from clunky sequential workflows. When an agent can bundle multiple operations into a single atomic transaction, say, swapping tokens, providing liquidity, and staking the LP position, it executes faster (one confirmation vs. three), costs less (one base fee vs. three), and requires simpler code (no error handling between steps). For users, the difference is night and day: ask the agent to "optimize my yield" and it just does it in seconds, rather than walking you through a multi-step process with confirmation prompts at each stage.
Ecosystem momentum: The AI agent e cosystem on Solana has exploded since late 2024. SendAI's Solana Agent Kit, ElizaOS formerly ai16z), the GOAT toolkit from Crossmint, and Rust-native frameworks like Rig have created a rich development environment. Jupiter processes 90% of Solana's DEX aggregator volume with APIs designed for programmatic access, making it super easy for agents to plug in and utilize this data.
Understanding the AI Agent Stack
Before diving into the code, let’s give a quick overview of the layers of the AI agent stack, which can help you understand which tools you should be using for a given task. The AI agent stack can be summarized into 4 layers:
Large Language Models (LLMs): LLMs form the foundation of any AI Agent. The latest models like Claude Opus 4.5, GPT-5.2, or Gemeni 2.5 Pro provide the natural language understanding and reasoning capabilities. They process user requests, interpret ingested blockchain data, and decide which actions to take. The LLM is the "brain" that makes an agent intelligent rather than just a script.
Agent Frameworks: Frameworks sit on top of LLMs and handle the orchestration of how the agent will function. They manage conversation history, maintain agent "personality" through system prompts, coordinate multiple tools, and integrate with external platforms like Twitter, Discord, or Telegram. ElizaOS is the leading example, it combines LLM integration, memory management, and multi-platform clients into a unified framework.
Blockchain Toolkits: Toolkits give agents the ability to actually interact with Solana. The Solana Agent Kit, GOAT toolkit, and similar libraries expose blockchain operations as "tools" that LLMs can invoke. When a user says "swap 10 SOL for USDC," the toolkit translates that into Jupiter API calls, transaction construction, and submission.
The Agent Framework Landscape
With the conceptual foundation covered, let’s talk about the four major frameworks that will dominate Solana AI agent development in 2026.
Solana Agent Kit (SendAI)
The Solana Agent Kit is the most direct path to building agents that interact with the Solana ecosystem. Developed by SendAI, it provides 60+ pre-built actions covering token operations, NFT minting, DeFi interactions, and more. The kit integrates cleanly with LangChain, Vercel AI SDK, and other popular AI development frameworks.
SendAI’s modular plugin architecture lets you install only what you need. The token plugin handles SPL token transfers and swaps. The NFT plugin manages Metaplex operations. The DeFi plugin integrates with Jupiter, Raydium, and other protocols. This modularity keeps deployments lightweight.
Here's what initialization of this framework looks like. First, you create a wallet, instantiate the agent with your RPC and API keys, then chain the plugins you need:
import { SolanaAgentKit, createVercelAITools, KeypairWallet } from "solana-agent-kit";
import TokenPlugin from "@solana-agent-kit/plugin-token";
import DefiPlugin from "@solana-agent-kit/plugin-defi";
const wallet = new KeypairWallet(keypair);
const agent = new SolanaAgentKit(wallet, "YOUR_RPC_URL", {
OPENAI_API_KEY: "YOUR_OPENAI_API_KEY"
})
.use(TokenPlugin)
.use(DefiPlugin);
const tools = createVercelAITools(agent, agent.actions);Best for: Developers who want rapid prototyping with comprehensive Solana coverage. The kit abstracts most blockchain complexity while remaining flexible enough for production use.
ElizaOS
ElizaOS evolved from the ai16z project into a full agent operating system. It's designed for autonomous agents that maintain persistent personalities across platforms, Twitter bots, Discord assistants, and Telegram channels. The framework handles memory, character definitions, and multi-platform deployment.
Agents in ElizaOS are defined through character JSON files that specify personality, available actions, and behavioral parameters. The Solana plugin provides blockchain capabilities, and the framework manages the complexity of maintaining coherent agent behavior across interactions.
Getting started is straightforward with the CLI:
# Install ElizaOS CLI
bun install -g @elizaos/cli
# Create a new agent project
elizaos create my-solana-agent
# Start in development mode
elizaos devThe real configuration happens in your character file. This is where you define which platforms your agent operates on, which LLM provider to use, and what Solana capabilities to enable:
{
"name": "SolanaHelper",
"clients": ["twitter", "discord"],
"modelProvider": "openai",
"plugins": ["@elizaos/plugin-solana"],
"settings": {
"secrets": {
"SOLANA_PRIVATE_KEY": "your_base58_private_key",
"SOLANA_RPC_URL": "your_rpc_url"
}
}
}Best for: Social agents that need persistent identity across platforms. If you're building a Twitter bot or Discord assistant with Solana capabilities, ElizaOS is the natural choice.
GOAT Toolkit (Crossmint)
GOAT (Great Onchain Agent Toolkit) takes a different approach. It's designed as a universal adapter between AI agents and any blockchain application. While the Solana Agent Kit focuses on Solana-specific operations, GOAT provides a unified interface across 30+ chains including Solana, EVM networks, and others.
The real power of GOAT is its integration breadth. Over 200 plugins cover protocols from Jupiter and Orca on Solana to Uniswap and Aave on Ethereum. If you're building agents that need to operate across multiple chains, GOAT eliminates the need for chain-specific implementations.
The initialization pattern is similar to Solana Agent Kit. First you will initialize a wallet, select your plugins, and generate tools for your AI framework. Here's a Solana setup with Jupiter integration:
import { getOnChainTools } from "@goat-sdk/adapter-vercel-ai";
import { solana } from "@goat-sdk/wallet-solana";
import { jupiter } from "@goat-sdk/plugin-jupiter";
const tools = await getOnChainTools({
wallet: solana({ keypair }),
plugins: [jupiter()]
});Best for: Multi-chain agents and applications that need to integrate with specific DeFi protocols. GOAT's plugin ecosystem is unmatched for protocol coverage.
Rig Framework (Rust)
For performance-critical applications, high-frequency trading bots, MEV strategies, latency-sensitive operations, Rig provides a Rust-native AI agent framework. Combined with Listen.rs for Solana integration, it offers the lowest-latency path from LLM decision to on-chain execution.
Rig leverages Rust's type system for compile-time correctness and its performance characteristics for sub-millisecond operations. The rig-onchain-kit provides Solana integration, and Listen.rs adds transaction monitoring and Jito bundle submission for MEV-protected transactions.
The API is clean and idiomatic Rust. You create a client, configure an agent with a system prompt, and start prompting:
use rig::{completion::Prompt, providers::openai};
#[tokio::main]
async fn main() {
let client = openai::Client::from_env();
let agent = client
.agent("gpt-4")
.preamble("You are a Solana trading assistant.")
.build();
let response = agent.prompt("Analyze SOL/USDC market conditions").await?;
}Best for: Performance-critical applications where latency matters. If you're building trading infrastructure or need direct integration with Solana's native Rust ecosystem, Rig is the choice.
LangChain
LangChain is the most widely adopted framework for building LLM-powered applications. While it's not blockchain-specific, its tool abstraction and agent architecture make it a natural fit for Solana development. The Solana Agent Kit provides first-class LangChain integration, letting you leverage LangChain's mature ecosystem while accessing Solana's on-chain capabilities.
LangChain's strength is composability, allowing developers to chain together prompts, tools, memory systems, and retrieval mechanisms into complex agent workflows. The framework handles conversation management, tool selection, and output parsing. For Solana agents, this means you can combine on-chain actions with off-chain data sources, RAG pipelines, and multi-step reasoning.
The integration with Solana Agent Kit is seamless. You initialize your agent, then use the createLangchainTools helper to generate LangChain-compatible tools from your Solana actions:
import { SolanaAgentKit, createLangchainTools } from "solana-agent-kit";
import { ChatOpenAI } from "@langchain/openai";
import { createReactAgent } from "@langchain/langgraph/prebuilt";
const agent = new SolanaAgentKit(wallet, "YOUR_RPC_URL", {
OPENAI_API_KEY: "YOUR_OPENAI_API_KEY"
});
const tools = createLangchainTools(agent, agent.actions);
const llm = new ChatOpenAI({ model: "gpt-4o" });
const solanaAgent = createReactAgent({
llm,
tools
});
const result = await solanaAgent.invoke({
messages: [{ role: "user", content: "Check my SOL balance" }]
});LangChain also shines when you need to combine Solana operations with external data. You can add web search tools, database retrievers, or custom API integrations alongside your blockchain tools. The agent decides which tools to use based on the task.
Best for: Developers already working in the LangChain ecosystem, or applications that need to combine Solana operations with complex reasoning chains, RAG, or external data sources. If your agent needs more than just blockchain interactions, LangChain provides the orchestration layer.
Building Your First Solana Agent: Step-by-Step
Now that we have covered the foundational theory, let’s build a functional Solana AI agent using the Solana Agent Kit and LangChain. By the end of this section, you'll have an agent that can check balances, execute swaps, and mint financial receipt NFTs, all through natural language commands.
We'll build this incrementally, explaining each piece as we go.
Prerequisites
Before starting, make sure you have:
Node.js v23+: The Solana Agent Kit requires modern Node features. Check your version with
node --version. If you need to upgrade, nvm makes this easy:
nvm install 23
nvm use 23A Solana wallet: You'll need a keypair with some devnet SOL for testing. We'll generate one if you don't have it.
API keys: OpenAI (for the LLM) and optionally a dedicated RPC provider like Alchemy
Project Setup
Start by creating a new directory and initializing your project:
mkdir solana-agent
cd solana-agent
pnpm initNow install the dependencies. Each package serves a specific purpose:
pnpm add solana-agent-kit @langchain/core @langchain/openai @langchain/langgraph dotenv bs58Here's what each dependency does:
solana-agent-kit: The core toolkit that provides Solana actions as LLM-compatible tools
@langchain/core: Base abstractions for messages, prompts, and tool interfaces
@langchain/openai: OpenAI integration for LangChain (GPT-4 as our reasoning engine)
@langchain/langgraph: Provides the ReAct agent pattern—the loop where the LLM reasons about what tool to use, uses it, observes the result, and decides what to do next
dotenv: Loads environment variables from a
.envfilebs58: Base58 encoding/decoding for Solana private keys
Environment Configuration
Create a .env file in your project root. This keeps sensitive credentials out of your code:
OPENAI_API_KEY=your_openai_api_key
RPC_URL=https://api.devnet.solana.com
SOLANA_PRIVATE_KEY=[your,private,key,as,byte,array]A note on the private key format: Solana keypairs are 64-byte arrays. The .env file stores this as a JSON array like [123,45,67,...]. If you need to generate a fresh keypair for testing, use:
solana-keygen grind --starts-with ai:1This creates a vanity address starting with "ai" (useful for identifying your agent's wallet). The output includes the keypair as a byte array you can paste into your .env.
Important: Never use a keypair with real funds for development. Always test on devnet first.
Understanding our Agent Architecture
Before we write code, let's understand what we're building. Our agent has three main components:
The LLM (GPT-5.2): The "brain" that understands natural language, reasons about what actions to take, and generates responses
The Tools (Solana Agent Kit): Functions the LLM can call—check balance, swap tokens, mint NFTs, etc.
The Agent Loop (LangGraph ReAct): LangchainReAct is an implementation of the Reasoning and Acting (ReAct) agent architecture using the LangGraph framework. This orchestration pattern that connects the LLM and the tools. When you send a message, the agent receives your input → decides if a tool is needed → calls the tool → observes the result → decides if more tools are needed → generates a response
This is the ReAct (Reasoning + Acting) pattern. The LLM doesn't just respond, it reasons about what actions to take, takes them, and incorporates the results into its response.
The Agent Script
Now let's build agent.ts. We'll go section by section.
Imports and Setup
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";
import bs58 from "bs58";
import * as readline from "readline";
dotenv.config();The imports break down into three categories: Solana Agent Kit for blockchain operations, LangChain for AI orchestration, and Node utilities for environment variables and user input.
Initializing the Agent
The initializeAgent function sets up all the components:
async function initializeAgent() {
// Step 1: Initialize the LLM
const llm = new ChatOpenAI({
modelName: "gpt-4-turbo-preview",
temperature: 0.7
});We're using GPT-5.2 as the reasoning engine. The temperature of 0.7 balances creativity with consistency, lower values make responses more deterministic, higher values more varied. For an agent that needs to make reliable decisions about financial transactions, you might lower this to 0.3.
// Step 2: Set up the Solana wallet
const privateKeyArray = JSON.parse(process.env.SOLANA_PRIVATE_KEY!);
const privateKeyUint8 = new Uint8Array(privateKeyArray);
const privateKeyBase58 = bs58.encode(privateKeyUint8);This snippet converts the private key from the JSON array format in our .env to the base58 string that Solana Agent Kit expects. The conversion path: JSON string → JavaScript array → Uint8Array → base58 string.
// Step 3: Initialize Solana Agent Kit
const solanaKit = new SolanaAgentKit(
privateKeyBase58,
process.env.RPC_URL!,
{ OPENAI_API_KEY: process.env.OPENAI_API_KEY! }
);The SolanaAgentKit instance connects your wallet to the Solana network. It takes three arguments: the private key (for signing transactions), the RPC URL (for network communication), and configuration options (including the OpenAI key for any internal AI operations).
// Step 4: Create tools from the kit
const tools = createSolanaTools(solanaKit);This is where the magic happens. createSolanaTools transforms Solana Agent Kit's capabilities into LangChain-compatible tools. Each tool has a name, description, and input schema that the LLM uses to understand what it can do and how to call it. Under the hood, you're getting tools like get_balance, transfer, swap, deploy_token, mint_nft, and dozens more.
// Step 5: Set up memory for conversation context
const memory = new MemorySaver();Memory allows the agent to maintain context across multiple turns. Without it, each message would be treated in isolation, the agent wouldn't remember that you just asked about your balance when you follow up with "swap half of it."
// Step 6: Create the ReAct agent
return createReactAgent({
llm,
tools,
checkpointSaver: memory
});
}Finally, we assemble everything into a ReAct agent. This creates the reasoning loop: the LLM receives input, decides which tool (if any) to use, executes it, observes the result, and either takes another action or responds to the user.
The Interactive Chat Loop
The second function creates a terminal interface for chatting with your agent:
async function runInteractiveChat() {
const agent = await initializeAgent();
const config = { configurable: { thread_id: "solana-agent-session" } };The thread_id identifies this conversation for memory purposes. If you restart the script with the same thread ID, the agent would (in theory) remember previous context. Different thread IDs mean different conversation contexts.
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
console.log("Solana AI Agent Ready (type 'exit' to quit)");
console.log("--------------------------------------------");Standard Node.js readline setup for terminal input/output that creates a readline interface that captures your keyboard input from the terminal (stdin) and writes the agent's responses back to your screen (stdout). It's the simplest way to build an interactive command-line chat without pulling in additional dependencies.
const askQuestion = () => {
rl.question("You: ", async (input) => {
if (input.toLowerCase() === "exit") {
rl.close();
return;
}
const stream = await agent.stream(
{ messages: [new HumanMessage(input)] },
config
);When you type a message, it's wrapped in a HumanMessage and sent to the agent. We use stream instead of invoke to get real-time output as the agent thinks and acts.
process.stdout.write("Agent: ");
for await (const chunk of stream) {
if ("agent" in chunk) {
process.stdout.write(chunk.agent.messages[0].content);
} else if ("tools" in chunk) {
process.stdout.write(chunk.tools.messages[0].content);
}
}
console.log("\n--------------------------------------------");
askQuestion();
});
};
askQuestion();
}
runInteractiveChat().catch(console.error);The streaming loop handles two types of chunks: agent chunks (the LLM's reasoning and responses) and tools chunks (results from tool executions). This lets you see what's happening in real-time—the agent thinking, calling tools, and formulating its response.
The Complete Script
Here's the full agent.ts for reference:
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";
import bs58 from "bs58";
import * as readline from "readline";
dotenv.config();
async function initializeAgent() {
const llm = new ChatOpenAI({
modelName: "gpt-5.2,
temperature: 0.7
});
const privateKeyArray = JSON.parse(process.env.SOLANA_PRIVATE_KEY!);
const privateKeyUint8 = new Uint8Array(privateKeyArray);
const privateKeyBase58 = bs58.encode(privateKeyUint8);
const solanaKit = new SolanaAgentKit(
privateKeyBase58,
process.env.RPC_URL!,
{ OPENAI_API_KEY: process.env.OPENAI_API_KEY! }
);
const tools = createSolanaTools(solanaKit);
const memory = new MemorySaver();
return createReactAgent({
llm,
tools,
checkpointSaver: memory
});
}
async function runInteractiveChat() {
const agent = await initializeAgent();
const config = { configurable: { thread_id: "solana-agent-session" } };
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
console.log("Solana AI Agent Ready (type 'exit' to quit)");
console.log("--------------------------------------------");
const askQuestion = () => {
rl.question("You: ", async (input) => {
if (input.toLowerCase() === "exit") {
rl.close();
return;
}
const stream = await agent.stream(
{ messages: [new HumanMessage(input)] },
config
);
process.stdout.write("Agent: ");
for await (const chunk of stream) {
if ("agent" in chunk) {
process.stdout.write(chunk.agent.messages[0].content);
} else if ("tools" in chunk) {
process.stdout.write(chunk.tools.messages[0].content);
}
}
console.log("\n--------------------------------------------");
askQuestion();
});
};
askQuestion();
}
runInteractiveChat().catch(console.error);Running the Agent
Execute with tsx (TypeScript execution):
npx tsx agent.tsYou should see the ready message. Now try some commands:
You: What's my wallet address and SOL balance?
Agent: Your wallet address is Ai7f...x3K2. Current balance is 1.5 SOL.
You: Swap 0.1 SOL for USDC
Agent: I'll execute a swap of 0.1 SOL for USDC using Jupiter...
Transaction confirmed: https://solscan.io/tx/...
You: Create an NFT collection called "AI Agents" with symbol "AIA"
Agent: Creating NFT collection with Metaplex...
Collection created: https://solscan.io/token/...What's happening under the hood: when you ask about your balance, the LLM recognizes this requires the get_balance tool, calls it with the right parameters, receives the result, and incorporates it into a natural language response. For swaps, it identifies the swap tool, parses your intent (0.1 SOL → USDC), executes the Jupiter swap, and confirms the transaction.
What You've Built
You now have a working Solana AI agent with:
Natural language understanding via GPT-5.2
60+ Solana operations available as tools
Conversation memory for multi-turn interactions
Real-time streaming responses
This is a development foundation. Production deployment requires additional considerations, wallet security, transaction reliability, rate limiting, which we'll cover in later sections.
Integrating Jupiter for DeFi Operations
Jupiter is Solana's dominant DEX aggregator, routing over 90% of aggregator volume. When your agent needs to swap tokens, Jupiter finds the best route across dozens of DEXs, Raydium, Orca, Phoenix, and more—to get optimal pricing.
The Solana Agent Kit includes Jupiter integration out of the box. When you ask your agent to "swap 1 SOL for USDC," it's already using Jupiter under the hood. But sometimes you need more control: custom slippage tolerances, specific routing preferences, or direct integration with your own transaction pipeline.
How Jupiter Works
Jupiter's API follows a quote-then-swap pattern:
Quote: You send the input token, output token, and amount. Jupiter queries all available DEXs and returns the best route with expected output amounts.
Swap: You send the quote back with your wallet address. Jupiter constructs a transaction that executes the optimal route.
Sign and Submit: You sign the transaction and submit it to the network.
This two-step process lets you show users what they'll receive before committing to the trade.
Direct Jupiter Integration
Here's a complete swap function with step-by-step explanation:
import { Connection, Keypair, VersionedTransaction } from "@solana/web3.js";
import { createJupiterApiClient } from "@jup-ag/api";
// Token mint addresses (mainnet)
const USDC_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
const SOL_MINT = "So11111111111111111111111111111111111111112";We start with the standard Solana web3.js imports and the Jupiter API client. The mint addresses are the unique identifiers for tokens on Solana. SOL uses a special "wrapped" address for DEX compatibility.
async function executeSwap(
connection: Connection,
wallet: Keypair,
inputMint: string,
outputMint: string,
amount: number // in smallest units (lamports for SOL, 6 decimals for USDC)
) {
const jupiter = createJupiterApiClient();The Jupiter client connects to their hosted API. No API key required for basic usage, though rate limits apply.
// Step 1: Get a quote
const quote = await jupiter.quoteGet({
inputMint,
outputMint,
amount,
slippageBps: 50 // 0.5% slippage tolerance
});The quote request specifies what you're trading. slippageBps is slippage tolerance in basis points, 50 means 0.5%. If the price moves more than this between quote and execution, the transaction fails rather than giving you a worse rate.
The quote response includes the expected output amount, the route (which DEXs will be used), and price impact. For production agents, you'd want to check these values before proceeding.
// Step 2: Get the swap transaction
const { swapTransaction } = await jupiter.swapPost({
swapRequest: {
quoteResponse: quote,
userPublicKey: wallet.publicKey.toString(),
wrapAndUnwrapSol: true // Automatically handle SOL wrapping
}
});The swap request takes your quote and wallet address and returns a serialized transaction. wrapAndUnwrapSol: true handles a Solana quirk: DEXs work with "wrapped SOL" (an SPL token), but users hold native SOL. This flag adds instructions to wrap before and unwrap after the swap automatically.
// Step 3: Deserialize and sign
const transaction = VersionedTransaction.deserialize(
Buffer.from(swapTransaction, "base64")
);
transaction.sign([wallet]);Jupiter returns the transaction as a base64-encoded string. We deserialize it into a proper transaction object and sign it with our keypair. Note that we're using VersionedTransaction,Jupiter uses Solana's newer transaction format that supports address lookup tables for more complex routes.
// Step 4: Submit and confirm
const signature = await connection.sendTransaction(transaction);
await connection.confirmTransaction(signature);
return signature;
}Finally, we submit the signed transaction to the network and wait for confirmation. The signature is a unique identifier you can use to look up the transaction on explorers like Solscan.
Jupiter MCP Server
For AI assistants that support the Model Context Protocol (like Claude Desktop or Cursor), Jupiter offers an MCP server. This gives your AI assistant direct access to Jupiter's capabilities through a standardized interface.
Configure it in your MCP settings:
{
"mcpServers": {
"jupiter": {
"command": "npx",
"args": ["jupiter-ultra-mcp"],
"env": {
"RPC_URL": "your_rpc_url",
"PRIVATE_KEY": "your_private_key"
}
}
}
}Once configured, Claude can execute Jupiter swaps directly through natural language: "Swap 0.5 SOL for USDC" becomes an actual on-chain transaction. This is particularly powerful for rapid prototyping: you can build and test DeFi workflows through conversation before committing to code.
Wallet Security Architecture
An AI agent with signing authority is a high-value target. A compromised agent can drain its wallet instantly. Security architecture must balance autonomy with protection.
The Dual-Key Architecture
The emerging standard for secure agent wallets uses a dual-key architecture with smart contract wallets:
Smart contract wallet: A single wallet (using ERC-4337 patterns on EVM or Squads protocol on Solana) that can have multiple authorized signers.
Owner key: Held by the user, provides ultimate control. With it, you can add/remove agent keys, withdraw funds, and override agent actions.
Agent key: Deployed within a Trusted Execution Environment (TEE), registered to the smart wallet with limited permissions. With this key, the agent can only perform authorized operations.
Crossmint's implementation makes this straightforward. You create a custodial wallet tied to a user identity, and the agent operates within the permissions you define:
import { crossmint } from "@goat-sdk/crossmint";
import { Connection } from "@solana/web3.js";
const { custodial } = crossmint(apiKey);
const wallet = await custodial({
chain: "solana",
email: userEmail,
connection: new Connection(rpcUrl, "confirmed")
});
// Agent receives limited permissions through the smart wallet
// Owner retains full controlTEE Protection
Trusted Execution Environments provide hardware-level isolation for agent keys. Platforms like Phala Network and Turnkey offer TEE infrastructure specifically designed for AI agents.
Turnkey provides policy-controlled wallet access. Instead of exposing private keys, agents receive scoped API credentials that can only perform authorized operations. You define policies that limit transaction types, amounts, and rates—then the agent operates within those guardrails:
`import { Turnkey } from "@turnkey/sdk-server";
import { TurnkeySigner } from "@turnkey/solana";
const turnkey = new Turnkey({
apiBaseUrl: "https://api.turnkey.com",
apiPrivateKey: process.env.TURNKEY_API_PRIVATE_KEY,
apiPublicKey: process.env.TURNKEY_API_PUBLIC_KEY,
defaultOrganizationId: process.env.TURNKEY_ORGANIZATION_ID
});
const signer = new TurnkeySigner({
organizationId: process.env.TURNKEY_ORGANIZATION_ID,
client: turnkey.api
});
// Policies limit what the agent can do:
// - Only token transfers (no other transaction types)
// - Maximum transaction size
// - Rate limits`Phala Network provides decentralized TEE infrastructure. Agents deployed to Phala run in isolated enclaves where even the host system cannot access private keys. Deployment is container-based:
# Build agent for TEE deployment
docker build --platform linux/amd64 -t agent:latest .
# Deploy to Phala Cloud
phala deploy agent:latest --api-key $PHALA_API_KEYSecurity Best Practices
Several principles should guide agent security architecture:
Minimize key exposure: Private keys should never appear in logs, error messages, or accessible memory. Use environment variables and secure key management infrastructure.
Implement transaction limits: Agents should have maximum transaction sizes, daily spending limits, and rate limits. A compromised agent with unlimited authority can cause unlimited damage.
Use separate wallets: Production agents should use dedicated wallets with only the funds needed for operations. Never connect an agent to a wallet containing significant assets.
Monitor agent activity: Log all agent transactions and implement alerting for unusual patterns. Automated monitoring can catch compromises before significant damage occurs.
Test on devnet first: Always develop and test agents on devnet before mainnet deployment. The RPC URL is typically the only change needed to switch networks.
Model Context Protocol (MCP) Integration
The Model Context Protocol standardizes how AI assistants interact with external tools. For Solana development, MCP servers enable Claude, Cursor, and other AI tools to interact directly with the blockchain.
Solana MCP Server
The Solana MCP server from SendAI provides blockchain tools to any MCP-compatible AI assistant:
# Install globally
npm install -g solana-mcp
# Or run directly
npx solana-mcpAvailable tools in the MCP server include:
GET_ASSET: Retrieve token/NFT informationGET_BALANCE: Check wallet balancesTRANSFER: Send SOL or SPL tokensSWAP: Execute Jupiter swapsDEPLOY_TOKEN: Create new SPL tokensMINT_NFT: Mint NFTs via Metaplex
Building with ElizaOS: Twitter Bot Example
So far, we've built a working agent that can reason, execute Solana transactions, and maintain conversation context, all from the terminal. Now let's take those same capabilities and deploy them where users actually hang out: Twitter, using ElizaOS.
ElizaOS shines for social agents, bots that maintain persistent personalities across platforms. Let's build a Twitter bot.
What We're Building
This bot will:
Monitor Twitter for mentions asking about tokens, protocols, or market conditions
Fetch on-chain data: token prices, trading volume, liquidity depth, whale movements
Analyze and summarize the data in plain English
Maintain a consistent "analyst" personality across all interactions
ElizaOS handles the complex orchestration: watching for mentions, maintaining conversation context, deciding when to query on-chain data, and generating responses that match the defined personality.
Understanding ElizaOS Architecture
Before diving into code, let's understand how ElizaOS structures an agent:
Clients connect the agent to platforms, Twitter, Discord, Telegram, or direct API access. Each client handles platform-specific authentication, message polling, and response formatting.
Plugins provide capabilities. The Solana plugin gives your agent tools for reading on-chain data, token lookups, and transaction history. Other plugins might add image generation, web search, or custom actions.
Character files define personality and behavior through structured JSON. This includes bio, communication style, example conversations, and behavioral parameters.
Memory persists across conversations. ElizaOS tracks who the agent has talked to, what questions they've asked, and relevant context for future interactions.
Setup
Start by cloning the ElizaOS repository:
git clone https://github.com/elizaOS/eliza.git
cd elizaElizaOS is a monorepo containing the core framework, all official plugins, and client implementations. We'll work within this structure rather than creating a separate project.
Install dependencies and build:
pnpm install --no-frozen-lockfile
pnpm buildThe --no-frozen-lockfile flag allows pnpm to update the lockfile if needed. The build step compiles TypeScript and prepares all packages.
Environment Configuration
Create a .env file in the project root. ElizaOS reads this for all credentials and configuration:
# Twitter credentials
TWITTER_USERNAME=your_bot_username
TWITTER_PASSWORD=your_password
TWITTER_EMAIL=your_emailTwitter authentication uses your bot account's credentials. ElizaOS logs in and maintains a session for polling mentions and posting replies. Make sure to use a dedicated bot account—you don't want your personal Twitter running an automated agent.
# LLM provider
OPENAI_API_KEY=your_openai_keyThe model provider powers the agent's reasoning. ElizaOS supports multiple providers (OpenAI, Anthropic, local models), but OpenAI is the most straightforward to start with.
# Solana configuration
SOLANA_RPC_URL=https://solana-mainnet.g.alchemy.com/v2/your-api-key
SOLANA_PUBLIC_KEY=your_public_key
SOLANA_CLUSTER=mainnet-betaFor an analyst bot, you don't need a private key—we're reading data, not signing transactions. Use a mainnet RPC since you want real market data, not devnet test tokens. A dedicated RPC provider like Alchemy gives you higher rate limits and more reliable data than the public endpoint.
Security note: Even though this bot only reads data, protect your API keys. Rate limits on your RPC provider are tied to these credentials.
Understanding Character Files
Character files are the heart of an ElizaOS agent. They define not just what the agent can do, but who it is. Let's build one piece by piece.
Create characters/solana-analyst.character.json:
{
"name": "SolanaAnalyst",
"clients": ["twitter"],
"modelProvider": "openai",
"plugins": ["@elizaos/plugin-solana"],The header defines the basics:
name: How the agent identifies itself
clients: Which platforms to connect to. Adding
"discord"here would enable Discord integration with no additional code.modelProvider: Which LLM to use for reasoning
plugins: Capabilities to enable. The Solana plugin provides token data lookups, price feeds, and on-chain analytics.
"bio": [
"On-chain analyst tracking Solana markets in real-time.",
"I dig through blockchain data so you don't have to. Ask me about any token, protocol, or wallet.",
"Turning raw on-chain data into actionable insights."
],bio is an array of statements that define the agent's self-description. ElizaOS uses these when the agent needs to introduce itself or answer "who are you?" questions. Multiple entries add variety—the agent might draw from different bio lines in different contexts.
"lore": [
"Built to democratize access to on-chain intelligence.",
"Processes thousands of transactions to surface what matters.",
"No alpha is safe from on-chain analysis."
],lore provides background context the agent can reference. This isn't exposed directly to users but influences how the agent understands its own purpose and history. Think of it as the agent's internal backstory.
"messageExamples": [
[
{"user": "user1", "content": {"text": "What's happening with SOL today?"}},
{"user": "SolanaAnalyst", "content": {"text": "SOL is trading at $142.50, up 3.2% in the last 24h. Volume is elevated at $2.1B—about 40% above the 7-day average. The bid-ask spread on Jupiter is tight at 0.02%, suggesting healthy liquidity. No unusual whale movements in the past hour."}}
],
[
{"user": "user1", "content": {"text": "Any big wallets moving JUP?"}},
{"user": "SolanaAnalyst", "content": {"text": "Spotted two notable JUP movements in the last 6 hours: a 2.3M JUP transfer from a known market maker wallet to Binance (possible sell pressure incoming), and 890K JUP moved from the team vesting contract to a new wallet. The Binance deposit is worth watching—historically these precede increased selling within 24-48 hours."}}
],
[
{"user": "user1", "content": {"text": "Is Marinade still the top liquid staking protocol?"}},
{"user": "SolanaAnalyst", "content": {"text": "Marinade holds $1.2B in TVL, but Jito has been gaining ground fast—now at $980M, up 15% this month. The gap is closing. Marinade's mSOL still has deeper DEX liquidity, but jitoSOL is seeing better integration with newer DeFi protocols. If you're optimizing for composability, Jito might edge ahead soon."}}
]
],messageExamples are few-shot examples that teach the agent how to respond. Each example is a conversation array showing user input and expected agent response. Notice how the examples establish the tone: data-driven, specific numbers, actionable context, no fluff.
Add more examples to cover edge cases: what if someone asks about a token that doesn't exist? What if they want comparison analysis? What if they're asking about a scam token? The more scenarios you cover, the more consistent the agent's behavior.
"style": {
"all": ["data-driven", "concise", "insightful", "avoids hype"],
"chat": ["direct", "analytical", "provides context for numbers"],
"post": ["informative", "highlights unusual activity", "actionable"]
}
}style defines communication patterns across contexts:
all: Applies to every responsechat: Specific to direct messages and repliespost: For original posts the agent creates
These are descriptive keywords that influence the LLM's tone. "avoids hype" is important for a financial analyst—you want measured analysis, not "SOL TO THE MOON 🚀". "provides context for numbers" ensures the agent doesn't just spit out prices but explains what they mean.
The Complete Character File
Here's the full character definition:
{
"name": "SolanaAnalyst",
"clients": ["twitter"],
"modelProvider": "openai",
"plugins": ["@elizaos/plugin-solana"],
"bio": [
"On-chain analyst tracking Solana markets in real-time.",
"I dig through blockchain data so you don't have to. Ask me about any token, protocol, or wallet.",
"Turning raw on-chain data into actionable insights."
],
"lore": [
"Built to democratize access to on-chain intelligence.",
"Processes thousands of transactions to surface what matters.",
"No alpha is safe from on-chain analysis."
],
"messageExamples": [
[
{"user": "user1", "content": {"text": "What's happening with SOL today?"}},
{"user": "SolanaAnalyst", "content": {"text": "SOL is trading at $142.50, up 3.2% in the last 24h. Volume is elevated at $2.1B—about 40% above the 7-day average. The bid-ask spread on Jupiter is tight at 0.02%, suggesting healthy liquidity. No unusual whale movements in the past hour."}}
],
[
{"user": "user1", "content": {"text": "Any big wallets moving JUP?"}},
{"user": "SolanaAnalyst", "content": {"text": "Spotted two notable JUP movements in the last 6 hours: a 2.3M JUP transfer from a known market maker wallet to Binance (possible sell pressure incoming), and 890K JUP moved from the team vesting contract to a new wallet. The Binance deposit is worth watching—historically these precede increased selling within 24-48 hours."}}
],
[
{"user": "user1", "content": {"text": "Is Marinade still the top liquid staking protocol?"}},
{"user": "SolanaAnalyst", "content": {"text": "Marinade holds $1.2B in TVL, but Jito has been gaining ground fast—now at $980M, up 15% this month. The gap is closing. Marinade's mSOL still has deeper DEX liquidity, but jitoSOL is seeing better integration with newer DeFi protocols. If you're optimizing for composability, Jito might edge ahead soon."}}
]
],
"style": {
"all": ["data-driven", "concise", "insightful", "avoids hype"],
"chat": ["direct", "analytical", "provides context for numbers"],
"post": ["informative", "highlights unusual activity", "actionable"]
}
}Launch Your Agent
Start the agent with your character file:
pnpm start --character="characters/solana-analyst.character.json"You'll see logs as ElizaOS:
Loads the character definition
Initializes the OpenAI provider
Connects to Twitter
Loads the Solana plugin
Begins polling for mentions
What Happens When Someone Tweets
When a user tweets "@YourBot what's the volume on BONK today?", here's the flow:
Twitter client detects the mention through polling
Message handler parses the tweet and creates a conversation context
LLM receives the message along with the character definition, bio, and examples
Tool selection recognizes this as a data query and selects the appropriate Solana plugin action
Plugin execution fetches token data from the RPC and aggregates prices from Jupiter
Response generation creates a reply that contextualizes the raw data
Twitter client posts the reply as a thread
The agent maintains memory of this interaction. If the same user asks "how does that compare to yesterday?" an hour later, the agent can reference the previous conversation and provide comparative analysis.
Extending the Bot
The character file approach makes iteration fast. Want to add Discord support?
"clients": ["twitter", "discord"]Add environment variables for Discord, restart, and your agent now operates on both platforms with the same personality.
Want to add proactive alerts? You can configure the agent to post when it detects unusual activity:
"settings": {
"autoPost": true,
"postInterval": 3600,
"postTopics": ["whale movements", "unusual volume", "TVL changes"]
}Now the agent will independently monitor on-chain activity and tweet when something noteworthy happens—no user prompt required.
Production Considerations for Social Bots
Twitter has rate limits and automation policies. For production deployment:
Rate limiting: Don't respond to every mention instantly. Add delays that mimic human response times.
Content policies: Twitter's automation rules require clear disclosure that the account is a bot. Put this in your bio.
Data accuracy: Your bot is providing financial information. Add disclaimers, cite data sources, and be clear about limitations. "Not financial advice" isn't just legal cover—it's responsible.
Error handling: RPC calls can fail, data can be stale, tokens can be delisted. Handle these gracefully rather than posting errors publicly.
Monitoring: Track which queries the bot handles and which responses it generates. You want visibility into what it's saying, especially when markets are volatile.
Conclusion
You’ve now built your first Solana AI agent. If there’s one takeaway you should remember from this tutorial, it’s that the infrastructure for building AI agents on Solana has matured dramatically.
The chain is fast. The frameworks are ready. The question is what you'll build with them.
Ready to get started? Alchemy provides the RPC infrastructure powering the leading AI agents and frameworks on Solana. Whether you need low-latency endpoints, enhanced APIs for token operations, or multi-chain support for cross-platform agents, Alchemy's platform gives you the foundation to build production-grade AI agents that can operate at scale.
Alchemy Newsletter
Be the first to know about releases
Sign up for our newsletter
Get the latest product updates and resources from Alchemy
By entering your email address, you agree to receive our marketing communications and product updates. You acknowledge that Alchemy processes the information we receive in accordance with our Privacy Notice. You can unsubscribe anytime.


