How to Build an AI Agent On Solana
Learn how to build an AI agent that swap token, checks balance and transfers on Solana
AI agents are autonomous systems that perform operations or tasks without human intervention. These agents act independently, as set up by users. For example, if you set up your agent to send a reminder or a report to your friend, this agent will perform the task on your behalf without your friend knowing that the action was performed by itself.
In the blockchain context, AI agents can:
Execute token swaps when prices hit targets
Rebalance portfolios across DeFi protocols
Monitor wallets and automate transfers
Mint NFTs based on social media triggers
Core Stack of AI Agents
Just like every area of development has its own stack for building applications, AI agent development has its own stack, typically consisting of three layers:
Large Language Models (LLMs): The reasoning brain of every AI agent. LMs handle natural language understanding, interpret user requests, process blockchain data, and decide which actions to take.
Agent Frameworks: These define the agent's structure, personality, and interactions with external platforms. Examples include ElizaOS, LangChain, Rig, and AgentiPy.
Blockchain Toolkits: SDKs that enable agents to interact with networks like Solana. Examples include the Solana Agent Kit and GOAT Toolkit.
Why Are AI Agents Important in Blockchain?
Simplification of Complex Tasks: AI agents can handle complex DeFi tasks, such as finding the best yield, rebalancing portfolios, or executing arbitrage trades faster than humans.
Enhanced Security: They provide continuous monitoring of vulnerabilities in smart contracts and wallets and detect fraudulent activity in real time.
Simplified User Experience (Web3 Adoption): AI agents act as intermediaries, translating natural-language requests into complex on-chain actions, reducing technical barriers for users.
Decentralized Autonomous Interactions: Agents can hold funds, sign transactions, and interact with dApps autonomously, creating new, self-sustaining, AI-driven economic ecosystems.
Intelligent Data Processing: They provide an insightful report on vast, immutable datasets on the blockchain to support better decision-making.
Now that you've learnt about AI agents, their core stack, and its importance. In this guide, you will be learning how to build an AI agent on Solana, a fast and growing blockchain network. This agent will be able to transfer SOL to USDC and check your account balance as seen below:

Prerequisites
You must have the following:
Node.js v23+ is installed on your laptop
API keys such as OpenAI (for the LLM) and Solana Devnet RPC URL (Optional: GetBlock Solana RPC URL)
Package manager installed on your laptop(Preferrably pnpm)
Devnet RPC URL is used for this guide. If you want to interact with Mainnet, then make use of GetBlock Solana RPC URL
Project Setup
Create a new project directory
Install the dependencies:
Packages Description
Package
What it does
@goat-sdk/core
The brain of GOAT — connects your wallet to AI-usable tools
@goat-sdk/wallet-solana
Lets GOAT read and control your Solana wallet
@goat-sdk/plugin-jupiter
Allows the agent to swap tokens using Jupiter DEX aggregator
@goat-sdk/plugin-spl-token
Lets the agent send, receive, and check balances of SPL tokens (USDC, BONK)
@goat-sdk/plugin-pumpfun
Lets the agent buy and sell tokens on Pump.fun
@goat-sdk/adapter-langchain
Converts GOAT tools into a format LangChain agents can call
@langchain/core
Core building blocks for the LangChain AI framework
@langchain/langgraph
Runs the agent loop — handles thinking, tool calling, and replying
@langchain/openai
Connects LangChain to OpenAI so GPT-4o can power the reasoning
@solana/web3.js
Standard library for talking to the Solana blockchain and RPCs
bs58
Decodes base58 private keys into a format the code can use
dotenv
Loads your .env file so secrets are not hardcoded in the source
Create a .env file and add the following details:
Create agent.ts file, this is where you will be building your AI agent
Import your dependencies:
Initialize your Agent
This:
Connect the AI agent to Solana Devnet and access your wallet to perform actions
Empower the agent with tools for swapping(
jupiter()), launch token(pumpfun()) and send and receive SPL token(splToken())Specify the language model to use
Create short-term memory so it remembers previous messages within the same chat session.
Create Interface for interaction:
This defines an interactive CLI chat loop between you and the AI agent and also logs any errors.
Run the agent using this command
You can make any request in any language, as seen below:
You can see that it interprets your natural language, uses the tools plugin to get the right response for it
Extend AI Agent capacity
Improve the capacity of your agent by adding more tools:
Mint NFT:
Best Practice
Store private keys in
.envonly — never commit this file.Use a dedicated burner wallet with minimal funds for testing
On mainnet, double-check all transactions before confirming.
Conclusion
In this guide, you have learn what AI agents are, their core stack, and how to build one for yourself to send, swap, launch a token, and check your account balance.
Additional Resources
Last updated
Was this helpful?