### Install Dependencies and Start Development Server Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/examples/examples-intro.mdx Commands to install project dependencies using npm and start the development server for an example. This is a common step for most examples. ```bash npm install npm run dev ``` -------------------------------- ### Clone Repository and Navigate to Example Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/examples/examples-intro.mdx Standard commands to clone the Agent Kit repository and navigate into a specific example directory. Ensure you have Git installed. ```bash git clone https://github.com/solana-labs/agent-kit-v2 cd agent-kit-v2 cd examples/[example-category]/[example-name] ``` -------------------------------- ### Basic MCP Server Setup Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/adapters/mcp/mcp-adapter-intro.mdx Set up the main server file, loading environment variables, initializing the wallet and agent, selecting actions, and starting the MCP server. ```javascript import { SolanaAgentKit, KeypairWallet } from "solana-agent-kit"; import { startMcpServer } from '@solana-agent-kit/adapter-mcp'; import TokenPlugin from '@solana-agent-kit/plugin-token'; import * as dotenv from "dotenv"; // Load environment variables dotenv.config(); // Initialize wallet with private key from environment const wallet = new KeypairWallet(process.env.SOLANA_PRIVATE_KEY); // Create agent with plugin const agent = new SolanaAgentKit( wallet, process.env.RPC_URL, { OPENAI_API_KEY: process.env.OPENAI_API_KEY, } ).use(TokenPlugin); // Select which actions to expose to the MCP server const finalActions = { BALANCE_ACTION: agent.actions.find((action) => action.name === "BALANCE_ACTION"), TOKEN_BALANCE_ACTION: agent.actions.find((action) => action.name === "TOKEN_BALANCE_ACTION"), GET_WALLET_ADDRESS_ACTION: agent.actions.find((action) => action.name === "GET_WALLET_ADDRESS_ACTION"), }; // Start the MCP server startMcpServer(finalActions, agent, { name: "solana-agent", version: "0.0.1" }); ``` -------------------------------- ### Install Dependencies with Bun Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/examples/social/tg-bot-starter/privy-tg-bot/README.md Use this command to install all necessary project dependencies when starting with the Privy TG Bot starter. ```bash bun install ``` -------------------------------- ### Start Server Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/examples/embedded-wallets/react-native.mdx Navigate to the server directory and start the development server. ```bash cd server yarn dev ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/examples/misc/agent-kit-langgraph/README.md Navigate to the agent-kit-langgraph example directory within the repository. ```bash cd examples/agent-kit-langgraph ``` -------------------------------- ### Start MCP Server with Solana Agent Kit Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/@solana-agent-kit/adapter-mcp/README.md Example JavaScript code to initialize the Solana Agent Kit, load plugins, define actions, and start the MCP server. Ensure environment variables for private key and RPC URL are set. ```javascript import { SolanaAgentKit, KeypairWallet } from "solana-agent-kit"; import { startMcpServer } from '@solana-agent-kit/adapter-mcp' import TokenPlugin from '@solana-agent-kit/plugin-token' import * as dotenv from "dotenv"; dotenv.config(); const wallet = new KeypairWallet(process.env.SOLANA_PRIVATE_KEY) const agent = new SolanaAgentKit( wallet, process.env.RPC_URL, { OPENAI_API_KEY: process.env.OPENAI_API_KEY, }, ).use(TokenPlugin); const finalActions = { BALANCE_ACTION: agent.actions.find((action) => action.name === "BALANCE_ACTION")!, TOKEN_BALANCE_ACTION: agent.actions.find((action) => action.name === "TOKEN_BALANCE_ACTION")!, GET_WALLET_ADDRESS_ACTION: agent.actions.find((action) => action.name === "GET_WALLET_ADDRESS_ACTION")!, }; startMcpServer(finalActions, agent, { name: "solana-agent", version: "0.0.1" }); ``` -------------------------------- ### Privy Integration Example Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/examples/embedded-wallets/privy.mdx This example shows how to use Privy's `useSolanaWallets` hook to get Solana wallets and then initialize `SolanaAgentKit` with Privy's transaction signing methods. It handles wallet readiness and creates AI tools. ```tsx import { useSolanaWallets } from '@privy-io/react-auth'; import { SolanaAgentKit, createVercelAITools } from 'solana-agent-kit'; import TokenPlugin from '@solana-agent-kit/plugin-token'; import { Connection, PublicKey } from '@solana/web3.js'; export function useSolanaAgent() { // Get Solana wallets from Privy const { wallets, ready } = useSolanaWallets(); // Create agent when wallet is ready const agent = useMemo(() => { if (ready && wallets.length > 0) { const wallet = wallets[0]; return new SolanaAgentKit( { publicKey: new PublicKey(wallet.address), // Handle transaction signing through Privy signTransaction: async (tx) => { return await wallet.signTransaction(tx); }, // Handle message signing through Privy signMessage: async (msg) => { return await wallet.signMessage(msg); }, // Handle transaction sending sendTransaction: async (tx) => { const connection = new Connection( import.meta.env.VITE_RPC_URL, 'confirmed' ); return await wallet.sendTransaction(tx, connection); }, // Handle multiple transaction signing signAllTransactions: async (txs) => { return await wallet.signAllTransactions(txs); }, }, import.meta.env.VITE_RPC_URL, {} ).use(TokenPlugin); } return null; }, [wallets, ready]); // Create tools for AI integration const tools = useMemo(() => { if (agent) { return createVercelAITools(agent, agent.actions); } return null; }, [agent]); return { agent, tools, isReady: ready && wallets.length > 0 }; } ``` -------------------------------- ### Example Implementation: Stake SOL and Get jupSOL Balance Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/integrations/token-operations/stake_sol.mdx This example demonstrates how to stake SOL using the Solana Agent Kit, log the transaction signature, and then check the balance of jupSOL tokens received. ```typescript import { SolanaAgentKit } from "solana-agent-kit"; async function stakeSOL(agent: SolanaAgentKit) { try { // Stake 1 SOL const signature = await agent.methods.stake(1); console.log("Staking successful:", signature); // You'll receive jupSOL tokens in return const jupsolBalance = await agent.methods.getBalance( new PublicKey("jupSoLaHXQiZZTSfEWMTRRgpnyFm8f6sZdosWBjx93v") ); console.log("jupSOL balance:", jupsolBalance); } catch (error) { console.error("Staking failed:", error); } } ``` -------------------------------- ### Start the Discord Bot Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/examples/social/discord-bot-starter/README.md Execute this command in the project's root directory to start the Discord bot after dependencies are installed. ```sh pnpm start ``` -------------------------------- ### Install Fraction SDK with Package Managers Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/fraction/sdk.mdx Install the Fraction SDK using your preferred package manager. ```bash pnpm install @sendaifun/fraction ``` ```bash npm install @sendaifun/fraction ``` ```bash yarn add @sendaifun/fraction ``` -------------------------------- ### Run the Example Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/examples/misc/agent-kit-langgraph/README.md Execute the main TypeScript file to run the LangGraph agent example. ```bash pnpm dev src/index.ts ``` -------------------------------- ### Install MCP Server via Script Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/adapters/mcp/mcp-adapter-intro.mdx Use this bash script for a quick and guided installation of the MCP server, including Node.js setup and configuration. ```bash curl -fsSL https://raw.githubusercontent.com/sendaifun/solana-mcp/main/scripts/install.sh -o solana-mcp-install.sh chmod +x solana-mcp-install.sh && ./solana-mcp-install.sh --backup ``` -------------------------------- ### Run Project Locally Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/examples/social/tg-bot-starter/basic-tg-bot/README.md Start the development server for the Telegram bot. This command is used after installing dependencies. ```bash pnpm run dev ``` -------------------------------- ### Install and Use Official Solana Agent Kit Plugins Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/MIGRATING.md Shows how to install official plugins like Token and Defi, and then integrate them into the Solana Agent Kit. ```bash npm install @solana-agent-kit/plugin-token @solana-agent-kit/plugin-defi ``` -------------------------------- ### Run the Telegram Bot with Bun Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/examples/social/tg-bot-starter/privy-tg-bot/README.md Execute this command to start the Telegram bot application after installing dependencies. ```bash bun run index.ts ``` -------------------------------- ### Install Solana Agent Kit and Plugins Source: https://context7.com/sendaifun/solana-agent-kit/llms.txt Install the core package, all available plugins, and the optional MCP adapter using npm. ```bash # Core package npm install solana-agent-kit # All plugins npm install @solana-agent-kit/plugin-token @solana-agent-kit/plugin-nft \ @solana-agent-kit/plugin-defi @solana-agent-kit/plugin-misc @solana-agent-kit/plugin-blinks # MCP adapter (optional) npm install @solana-agent-kit/adapter-mcp ``` -------------------------------- ### Install Solana Agent Kit Plugins Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/README.md Install all available plugins for the Solana Agent Kit using npm. This command installs the token, NFT, DeFi, misc, and blinks plugins. ```bash npm install @solana-agent-kit/plugin-token @solana-agent-kit/plugin-nft @solana-agent-kit/plugin-defi @solana-agent-kit/plugin-misc @solana-agent-kit/plugin-blinks ``` -------------------------------- ### Install DeFi Plugin Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/plugins/defi/defi-plugin-intro.mdx Install the DeFi plugin alongside the core Solana Agent Kit using npm. ```bash npm install solana-agent-kit @solana-agent-kit/plugin-defi ``` -------------------------------- ### Install Token Plugin Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/plugins/token/token-plugin-intro.mdx Install the Token plugin alongside the core Solana Agent Kit using npm. ```bash npm install solana-agent-kit @solana-agent-kit/plugin-token ``` -------------------------------- ### Main Tab Navigator Setup Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/examples/embedded-wallets/privy-sak-react-native/src/navigation/README.md Sets up a tab navigator for the main sections of the application, including a 'Home' tab with a custom icon. This example shows the basic structure for defining tabs. ```typescript function MainTabs() { return ( ( ), }} /> {/* Other tabs */} ); } ``` -------------------------------- ### Example Swap Implementation Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/integrations/defi-integration/jupiter_exchange_swaps.mdx This example demonstrates how to initialize the SolanaAgentKit and execute two different token swaps: SOL to USDC and USDC back to SOL with custom slippage. ```typescript import { SolanaAgentKit } from "solana-agent-kit"; import { PublicKey } from "@solana/web3.js"; async function executeSwaps(agent: SolanaAgentKit) { // Common token addresses const USDC = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"); const SOL = new PublicKey("So11111111111111111111111111111111111111112"); try { // Swap SOL for USDC const swap1 = await agent.methods.trade( USDC, 1 // 1 SOL ); console.log("SOL -> USDC swap:", swap1); // Swap USDC back to SOL const swap2 = await agent.methods.trade( SOL, 100, // 100 USDC USDC, 100 // 1% slippage ); console.log("USDC -> SOL swap:", swap2); } catch (error) { console.error("Swap failed:", error); } } ``` -------------------------------- ### Example Implementation of Balance Checks Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/integrations/token-operations/balance_check.mdx This example demonstrates how to import and use the Solana Agent Kit to check both your own and other wallets' SOL and SPL token balances. It includes logging the results to the console. ```typescript import { SolanaAgentKit } from "solana-agent-kit"; import { PublicKey } from "@solana/web3.js"; async function checkBalances(agent: SolanaAgentKit) { // Check own balances const mySolBalance = await agent.methods.getBalance(); console.log("My SOL balance:", mySolBalance); const myUsdcBalance = await agent.methods.getBalance( new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v") ); console.log("My USDC balance:", myUsdcBalance); // Check other wallet's balances const otherWallet = new PublicKey("GDEkQF7UMr7RLv1KQKMtm8E2w3iafxJLtyXu3HVQZnME"); const otherSolBalance = await agent.methods.getBalanceOther(otherWallet); console.log("Other wallet SOL balance:", otherSolBalance); const otherUsdcBalance = await agent.methods.getBalanceOther( otherWallet, new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v") ); console.log("Other wallet USDC balance:", otherUsdcBalance); } ``` -------------------------------- ### Install NFT Plugin Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/plugins/nft/nft-plugin-intro.mdx Install the NFT plugin alongside the core Solana Agent Kit using npm. ```bash npm install solana-agent-kit @solana-agent-kit/plugin-nft ``` -------------------------------- ### Install and Build Commands Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/CLAUDE.md Commands for installing dependencies, building all or specific packages, linting, formatting, testing, and cleaning build artifacts. ```bash pnpm install ``` ```bash pnpm run build ``` ```bash pnpm run build:core # Core package only ``` ```bash pnpm run build:plugin-token # Token plugin ``` ```bash pnpm run build:plugin-defi # DeFi plugin ``` ```bash pnpm run build:plugin-nft # NFT plugin ``` ```bash pnpm run build:plugin-misc # Misc plugin ``` ```bash pnpm run build:plugin-blinks # Blinks plugin ``` ```bash pnpm run build:adapter-mcp # MCP adapter ``` ```bash pnpm run lint # Check with Biome ``` ```bash pnpm run lint:fix # Auto-fix lint issues ``` ```bash pnpm run format # Format code with Biome ``` ```bash # Run tests (interactive - prompts for "agent" or "programmatic" mode) # Requires OPENAI_API_KEY, RPC_URL, SOLANA_PRIVATE_KEY in test/.env pnpm run test ``` ```bash pnpm run docs ``` ```bash pnpm run clean ``` -------------------------------- ### Example Prompts for Token Deployment Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/integrations/token-operations/deploy_spl_metaplex.mdx These are example natural language and LangChain tool prompts for deploying SPL tokens. The LangChain tool expects a JSON string input with token parameters. ```text "Deploy a new token called 'Awesome Token' with symbol 'AWE'" "Create a fungible token with 6 decimals and initial supply of 1 million" "Deploy an SPL token named 'Gaming Credits' with metadata URI pointing to my JSON file" ``` ```text // Basic token deployment { "name": "Awesome Token", "symbol": "AWE", "uri": "https://arweave.net/awesome-token.json" } // Token with custom decimals { "name": "Gaming Credits", "symbol": "GCRED", "uri": "https://arweave.net/metadata.json", "decimals": 6 } // Token with initial supply { "name": "Reward Points", "symbol": "RWPT", "uri": "https://arweave.net/reward-points.json", "decimals": 9, "initialSupply": 1000000 } ``` -------------------------------- ### Install Dependencies Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/examples/embedded-wallets/react-native.mdx Install all project dependencies using Yarn. ```bash yarn install ``` -------------------------------- ### Example Prompts for NFT Collection Deployment Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/integrations/nft-management/deploy_collection.mdx These are examples of natural language and LangChain tool prompts that can be used to deploy NFT collections with varying configurations. ```text "Create a new NFT collection called 'Awesome Art' with 5% royalties" "Deploy an NFT collection with metadata from my Arweave URI" "Launch a collection named 'Pixel Warriors' with 7.5% creator royalties" "Create a free collection with no royalties for my community" ``` ```text // Basic collection deployment { "name": "Awesome Art", "uri": "https://arweave.net/collection.json" } // Collection with royalties { "name": "Pixel Warriors", "uri": "https://arweave.net/metadata.json", "royaltyBasisPoints": 750 } // Community collection without royalties { "name": "Community Collection", "uri": "https://arweave.net/community.json", "royaltyBasisPoints": 0 } ``` -------------------------------- ### Example Implementation of Market Creation Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/integrations/defi-integration/openbook_market.mdx This TypeScript example demonstrates how to use the `openbookCreateMarket` method within a Solana Agent Kit application. It includes error handling for potential issues during market creation. ```typescript import { SolanaAgentKit } from "solana-agent-kit"; import { PublicKey } from "@solana/web3.js"; async function createTradingMarket(agent: SolanaAgentKit) { try { // Create USDC/SOL market const signatures = await agent.methods.openbookCreateMarket( new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"), // USDC new PublicKey("So11111111111111111111111111111111111111112"), // SOL 1, // 1 unit minimum order 0.01 // $0.01 minimum price increment ); console.log("Market created:", signatures); return signatures; } catch (error) { console.error("Market creation failed:", error); throw error; } } ``` -------------------------------- ### getActionExamples Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/solana-agent-kit/functions/getActionExamples.md Retrieves examples for a specified action. This function takes an 'Action' object as input and returns a string representing the examples associated with that action. ```APIDOC ## Function: getActionExamples() > **getActionExamples**(`action`): `string` Defined in: [packages/core/src/utils/actionExecutor.ts:45](https://github.com/scriptscrypt/solana-agent-kit/blob/8d48a57968ef71c6851a44a8efa685e80e815610/packages/core/src/utils/actionExecutor.ts#L45) Get examples for an action ### Parameters #### action [`Action`](../interfaces/Action.md) ### Returns `string` ``` -------------------------------- ### Install Dependencies Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/@solana-agent-kit/adapter-mcp/README.md Install project dependencies using pnpm. ```bash pnpm install ``` -------------------------------- ### Full Implementation Example for Deploying an Art Collection Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/integrations/nft-management/deploy_collection.mdx This example demonstrates a complete function to deploy a digital art NFT collection, including error handling and logging. ```typescript import { SolanaAgentKit } from "solana-agent-kit"; async function deployArtCollection(agent: SolanaAgentKit) { try { const collection = await agent.methods.deployCollection({ name: "Digital Art Collection", uri: "https://arweave.net/art-collection.json", royaltyBasisPoints: 500 // 5% royalty }); console.log("Collection deployed:", { address: collection.collectionAddress.toString(), name: "Digital Art Collection" }); return collection; } catch (error) { console.error("Collection deployment failed:", error); throw error; } } ``` -------------------------------- ### getActionExamples Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/solana-agent-kit/README.md Retrieves example actions that can be executed. ```APIDOC ## getActionExamples ### Description Retrieves a list of example actions that demonstrate the capabilities of the Solana Agent Kit. ### Signature getActionExamples(config: Config) ### Parameters #### Parameters - **config** (Config) - Required - The configuration object for the Solana Agent Kit. ### Response #### Success Response (200) - **ActionExample[]** - An array of action examples. ``` -------------------------------- ### Install MCP Adapter and Dependencies Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/adapters/mcp/mcp-adapter-intro.mdx Install the MCP adapter along with the core Solana Agent Kit and any necessary plugins like token support and dotenv for environment variables. ```bash npm install solana-agent-kit @solana-agent-kit/adapter-mcp @solana-agent-kit/plugin-token dotenv ``` -------------------------------- ### Install Misc Plugin Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/plugins/misc/misc-plugin-intro.mdx Install the plugin alongside the core Solana Agent Kit using npm. ```bash npm install solana-agent-kit @solana-agent-kit/plugin-misc ``` -------------------------------- ### Install Solana Agent Kit and Plugins Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/@solana-agent-kit/adapter-mcp/README.md Install the Solana Agent Kit, desired plugins, and the MCP utility along with dotenv for environment variable management. ```bash pnpm add solana-agent-kit @solana-agent-kit/plugin-token @solana-agent-kit/adapter-mcp dotenv ``` -------------------------------- ### Example LangChain Tool Prompts for Token Launch Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/integrations/defi-integration/launch_pumpfun.mdx These JSON examples demonstrate how to structure prompts for LangChain tools to launch tokens on Pump.fun, covering basic and advanced configurations. ```json // Basic token launch { "tokenName": "Rocket Dog", "tokenTicker": "RDOG", "description": "To the moon with man's best friend!", "imageUrl": "https://example.com/rdog.png" } // Advanced launch with socials and liquidity { "tokenName": "Sample Token", "tokenTicker": "SMPL", "description": "A sample token for demonstration", "imageUrl": "https://example.com/token.png", "twitter": "@sampletoken", "telegram": "t.me/sampletoken", "website": "https://sampletoken.com", "initialLiquiditySOL": 0.1 ``` -------------------------------- ### Install MCP Server from npm Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/adapters/mcp/mcp-adapter-intro.mdx Install the Solana MCP server globally or locally within your project using npm. ```bash # Install globally npm install -g solana-mcp # Or install locally in your project npm install solana-mcp ``` -------------------------------- ### Basic Feed Simulation Example Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/integrations/defi-integration/switchboard.mdx A straightforward example of simulating the SOL/USD price feed using its predefined constant. ```APIDOC ## Basic Feed Simulation Example This example simulates the SOL/USD feed using its constant and logs the result. ### Code Example ```typescript // Assuming FEEDS.SOL_USD is defined elsewhere as "GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR" const SOL_USD_FEED = "GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR"; try { const value = await agent.methods.simulateSwitchboardFeed(SOL_USD_FEED); console.log(`Current SOL price: $${value}`); } catch (error) { console.error(`Failed to simulate SOL/USD feed: ${error.message}`); } ``` ``` -------------------------------- ### Complete Example: Deploying Gaming Token Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/integrations/token-operations/deploy_spl_metaplex.mdx This complete TypeScript example demonstrates deploying an SPL token with custom metadata, including name, symbol, URI, decimals, and initial supply. ```typescript import { SolanaAgentKit } from "solana-agent-kit"; async function deployGamingToken(agent: SolanaAgentKit) { const tokenMetadata = { name: "Gaming Credits", symbol: "GCRED", uri: "https://example.com/token-metadata.json", decimals: 6, initialSupply: 1_000_000 }; const result = await agent.methods.deployToken( tokenMetadata.name, tokenMetadata.uri, tokenMetadata.symbol, tokenMetadata.decimals, tokenMetadata.initialSupply ); return result.mint.toString(); } ``` -------------------------------- ### Example Implementation of NFT Minting Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/integrations/nft-management/mint_nft.mdx A full TypeScript example demonstrating how to mint NFTs to both your own wallet and a specific recipient using the SolanaAgentKit. ```typescript import { SolanaAgentKit } from "solana-agent-kit"; import { PublicKey } from "@solana/web3.js"; async function mintCollectionNFTs(agent: SolanaAgentKit) { // Collection address const collection = new PublicKey("collection-address"); // Mint to own wallet const nft1 = await agent.methods.mintNFT( collection, { name: "My NFT #1", uri: "https://arweave.net/nft1.json" } ); console.log("Minted NFT:", nft1.mint.toString()); // Mint to recipient const recipient = new PublicKey("recipient-address"); const nft2 = await agent.methods.mintNFT( collection, { name: "Gift NFT #1", uri: "https://arweave.net/nft2.json" }, recipient ); console.log("Minted gift NFT:", nft2.mint.toString()); } ``` -------------------------------- ### Clone Solana Agent Kit Example Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/examples/README.md Use npx gitpick to clone a specific example from the Solana Agent Kit repository. Ensure you replace and with the desired values. ```bash npx gitpick sendaifun/solana-agent-kit/examples// ``` ```bash npx gitpick sendaifun/solana-agent-kit/examples/defi/market-making-agent ``` -------------------------------- ### Example MCP Server Configuration Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/examples/mcp/agent-kit-mcp-server/README.md An example JSON configuration for Claude Desktop's MCP server settings. This specifies the command to run, environment variables, and the project path. ```json { "mcpServers": { "agent-kit": { "command": "node", "env": { "RPC_URL": "your_solana_rpc_url_here", "SOLANA_PRIVATE_KEY": "your_private_key_here" }, "args": [ "/ABSOLUTE/PATH/TO/YOUR/PROJECT" ] } } } ``` -------------------------------- ### Start MCP Server with Actions and SolanaAgentKit Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/@solana-agent-kit/adapter-mcp/functions/startMcpServer.md Use this snippet to start the MCP server, exposing defined actions and integrating with the SolanaAgentKit. Ensure ACTIONS and SolanaAgentKit are properly imported and initialized. ```typescript import { ACTIONS } from "./actions"; import { startMcpServer } from "./mcpWrapper"; const solanaAgentKit = new SolanaAgentKit(); startMcpServer(ACTIONS, solanaAgentKit, { name: "solana-actions", version: "1.0.0" }); ``` -------------------------------- ### Full Example Implementation of Token Launch Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/integrations/defi-integration/launch_pumpfun.mdx This TypeScript code provides a complete example of launching a token on Pump.fun, including error handling and logging of the transaction result. ```typescript import { SolanaAgentKit } from "solana-agent-kit"; async function launchToken(agent: SolanaAgentKit) { try { const result = await agent.methods.launchPumpFunToken( "Rocket Dog", "RDOG", "The fastest dog-themed token on Solana!", "https://example.com/rdog.png", { twitter: "@rocketdogtoken", telegram: "t.me/rocketdog", website: "https://rocketdog.io", initialLiquiditySOL: 0.1, slippageBps: 10 } ); console.log("Token launched:", { mint: result.mint, metadata: result.metadataUri, tx: result.signature }); return result; } catch (error) { console.error("Token launch failed:", error); throw error; } } ``` -------------------------------- ### Initialize Solana Agent Kit with Plugins Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/README.md Initialize the Solana Agent Kit with a wallet and plugins. This example demonstrates initializing with a KeypairWallet and includes placeholders for your secret key, RPC URL, and OpenAI API key. It also shows how to create Vercel AI tools from the agent. ```typescript import { SolanaAgentKit, createVercelAITools, KeypairWallet } from "solana-agent-kit"; // or import createLangchainTools if using langchain or createOpenAITools for OpenAI agents 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 keyPair = Keypair.fromSecretKey(bs58.decode("YOUR_SECRET_KEY")) const wallet = new KeypairWallet(keyPair) // Initialize with private key and optional RPC URL const agent = new SolanaAgentKit( wallet, "YOUR_RPC_URL", { OPENAI_API_KEY: "YOUR_OPENAI_API_KEY", } ) // Add the plugins you would like to use .use(TokenPlugin) .use(NFTPlugin) .use(DefiPlugin) .use(MiscPlugin) .use(BlinksPlugin); // Create LangChain tools const tools = createVercelAITools(agent, agent.actions); ``` -------------------------------- ### Complete Transfer Implementation Example Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/integrations/token-operations/transfer_assets.mdx This example demonstrates how to perform both SOL and SPL token transfers within a single function. It includes necessary imports and logs the transaction signatures. ```typescript import { SolanaAgentKit } from "solana-agent-kit"; import { PublicKey } from "@solana/web3.js"; async function executeTransfers(agent: SolanaAgentKit) { // Transfer SOL const solTransfer = await agent.methods.transfer( new PublicKey("recipient"), 1.5 // 1.5 SOL ); console.log("SOL transfer:", solTransfer); // Transfer USDC const usdcTransfer = await agent.methods.transfer( new PublicKey("recipient"), 100, // 100 USDC new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v") ); console.log("USDC transfer:", usdcTransfer); } ``` -------------------------------- ### Clone Repository and Navigate Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/examples/embedded-wallets/crossmint-sak-v2/README.md Clone the project repository and navigate into the project directory. This is the initial step for setting up the project locally. ```bash git clone https://github.com/yourusername/crossmint-solana-agent.git cd crossmint-solana-agent ``` -------------------------------- ### Install and Run MCP Inspector Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/devrel-agents/jito.mdx Install the MCP Inspector tool globally using npm and run it to start a local testing environment for MCP services. ```bash npx @modelcontextprotocol/inspector ``` -------------------------------- ### Install Solana Agent Kit Docs MCP Server Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/using-llms/overview.mdx Install the Solana Agent Kit Docs MCP server using npx. This command sets up the necessary components for AI-powered interactions with the documentation. ```bash npx mint-mcp add docs.sendai.fun ``` -------------------------------- ### Get Main Domain LangChain Tool Prompt Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/integrations/defi-integration/alldomains.mdx This is an example of how to structure a prompt for the LangChain tool to get the main domain associated with an address. The 'address' field must be a valid public key. ```json { "address": "7nxQB..." } ``` -------------------------------- ### Example: Creating a SOL/USDC Pool Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/integrations/defi-integration/fluxbeam.mdx A practical example of creating a liquidity pool for SOL and USDC. This uses predefined constants for token addresses and demonstrates the `fluxbeamCreatePool` method with specific amounts. ```typescript const signature = await agent.methods.fluxbeamCreatePool( TOKENS.SOL, 1.5, // 1.5 SOL TOKENS.USDC, 10 // 10 USDC ); ``` -------------------------------- ### Start the development server Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/examples/embedded-wallets/crossmint.mdx Launch the development server to run the application locally. ```bash pnpm dev ``` -------------------------------- ### Build MCP Server from Source Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/adapters/mcp/mcp-adapter-intro.mdx Clone the repository, install dependencies, and build the project from source. ```bash git clone https://github.com/sendaifun/solana-mcp cd solana-mcp pnpm install pnpm run build ``` -------------------------------- ### Market Analysis Use Case Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/integrations/defi-integration/dexscreener.mdx Example of how to get a token's address from its ticker and then fetch its market pairs and data from DexScreener. ```typescript // Get token data including market pairs const address = await getTokenAddressFromTicker("SOL"); if (address) { // Analyze token pairs and market data const pairs = await getDexScreenerPairs(address); } ``` -------------------------------- ### Set Up Environment Variables Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/examples/embedded-wallets/turnkey.mdx Configure the .env.local file with necessary credentials for Turnkey, Solana, and OpenAI. Ensure all required fields are populated. ```dotenv NEXT_PUBLIC_TURNKEY_API_BASE_URL= NEXT_PUBLIC_TURNKEY_API_PUBLIC_KEY= NEXT_PUBLIC_TURNKEY_ORGANIZATION_ID= NEXT_PUBLIC_TURNKEY_API_PRIVATE_KEY= NEXT_PUBLIC_RPC_URL= OPENAI_API_KEY= ``` -------------------------------- ### Get Owned Domains LangChain Tool Prompt Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/integrations/defi-integration/alldomains.mdx This is an example of how to structure a prompt for the LangChain tool to retrieve owned domains. The 'owner' field should be a valid public key. ```json { "owner": "7nxQB..." } ``` -------------------------------- ### Initialize Solana Agent Kit with Plugins Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/packages/core/README.md Initialize the SolanaAgentKit with a wallet, RPC URL, and API keys. Use the .use() method to add desired plugins such as Token, NFT, Defi, Misc, and Blinks. ```typescript import { SolanaAgentKit, createVercelAITools, KeypairWallet } from "solana-agent-kit"; // or import createLangchainTools if using langchain or createOpenAITools if using OpenAI agents 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 keyPair = Keypair.fromSecretKey(bs58.decode("YOUR_SECRET_KEY")) const wallet = new KeypairWallet(keyPair) // Initialize with private key and optional RPC URL const agent = new SolanaAgentKit( wallet, "YOUR_RPC_URL", { OPENAI_API_KEY: "YOUR_OPENAI_API_KEY", } ) // Add the plugins you would like to use .use(TokenPlugin) .use(NFTPlugin) .use(DefiPlugin) .use(MiscPlugin) .use(BlinksPlugin); // Create LangChain tools const tools = createVercelAITools(agent, agent.actions); ``` -------------------------------- ### Root Navigator Setup Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/examples/embedded-wallets/privy-sak-react-native/src/navigation/README.md Configures the main stack navigator, conditionally rendering authentication or main app screens based on authentication status. Uses `useSelector` to get the authentication state. ```typescript // RootNavigator.tsx const Stack = createStackNavigator(); export const RootNavigator = () => { const isAuthenticated = useSelector(selectIsAuthenticated); return ( {!isAuthenticated ? ( // Auth Stack ) : ( // Main App Stack <> )} ); }; ``` -------------------------------- ### Get Chain Data with OKX DEX Integration Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/README.md This example shows how to fetch chain data, potentially for use with OKX DEX integration. Ensure all required OKX and Solana environment variables are set. ```typescript const txId = await agent.methods.getChainData( "So11111111111111111111111111111111111111112", "1000000000", "1100000000", 5000, "7Q2afV64in6N6SeZsAAB81TJzwDoD6zpqmHkzi9Dcavn" ) console.log('txId', txId) ``` -------------------------------- ### Get a Solana asset by its ID Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/README.md Get a Solana asset by its ID. ```APIDOC ## getAsset ### Description Get a Solana asset by its ID. ### Method `agent.methods.getAsset(agent, assetId)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript const asset = await agent.methods.getAsset(agent, "41Y8C4oxk4zgJT1KXyQr35UhZcfsp5mP86Z2G7UUzojU") ``` ### Response #### Success Response (200) - **asset** (object) - The Solana asset object. ``` -------------------------------- ### Clone Repository Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/examples/embedded-wallets/privy.mdx Clone the starter template using npx gitpick and navigate into the project directory. ```bash npx gitpick sendaifun/solana-agent-kit/examples/privy-agent-tanstack-starter -b v2 cd privy-solana-agent ``` -------------------------------- ### Get Drift account information Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/README.md Get drift account information. ```APIDOC ## driftUserAccountInfo ### Description Get drift account information. ### Method `agent.methods.driftUserAccountInfo(agent)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript const accountInfo = await agent.methods.driftUserAccountInfo(agent) ``` ### Response #### Success Response (200) - **accountInfo** (object) - An object containing drift account information. ``` -------------------------------- ### Create Project with gitpick Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/examples/embedded-wallets/privy-server-wallet.mdx Use gitpick to create a new project from the Privy Server wallet agent example. Navigate into the created directory. ```bash npx gitpick sendaifun/solana-agent-kit/examples/misc/privy-server-wallet-agent -b v2 cd privy-server-wallet-agent ``` -------------------------------- ### Get an inference for an specific topic from Allora Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/README.md Get an inference for an specific topic from Allora. ```APIDOC ## getInferenceByTopicId ### Description Get an inference for an specific topic from Allora. ### Method `agent.methods.getInferenceByTopicId(topicId)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript const inference = await agent.methods.getInferenceByTopicId(42); console.log("Allora inference for topic 42:", inference); ``` ### Response #### Success Response (200) - **inference** (object) - The inference data for the specified topic. ``` -------------------------------- ### Initialize MCP Server Project Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/adapters/mcp/mcp-adapter-intro.mdx Set up a new project directory for your MCP server and initialize it with npm. ```bash mkdir solana-agent-mcp cd solana-agent-mcp npm init -y ``` -------------------------------- ### Error Handling Example Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/integrations/non-financial/elfa_ai.mdx Provides an example of how to handle errors when using Elfa AI actions. ```APIDOC ## Error Handling ### Description All functions and tools include error handling. Here's an example of handling errors: ```typescript try { const result = await agent.methods.getTopMentionsByTicker("SOL"); if (!result.success) { console.error("API error:", result.error); // Handle error } else { console.log("Top mentions:", result.data); // Process data } } catch (error) { console.error("Exception:", error.message); // Handle exception } ``` ``` -------------------------------- ### Initialize Solana Agent Kit and MCP Server Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/setup/quickstart.mdx Set up the Solana Agent Kit with a wallet, RPC URL, and API keys. Expose specific actions and start the MCP server to allow external interactions. ```javascript import { SolanaAgentKit, KeypairWallet } from "solana-agent-kit"; import { startMcpServer } from '@solana-agent-kit/adapter-mcp'; import TokenPlugin from '@solana-agent-kit/plugin-token'; import * as dotenv from "dotenv"; // Load environment variables dotenv.config(); // Initialize wallet with private key from environment const wallet = new KeypairWallet(process.env.SOLANA_PRIVATE_KEY); // Create agent with plugin const agent = new SolanaAgentKit( wallet, process.env.RPC_URL, { OPENAI_API_KEY: process.env.OPENAI_API_KEY, }, ).use(TokenPlugin); // Select which actions to expose to the MCP server const finalActions = { BALANCE_ACTION: agent.actions.find((action) => action.name === "BALANCE_ACTION")!, TOKEN_BALANCE_ACTION: agent.actions.find((action) => action.name === "TOKEN_BALANCE_ACTION")!, GET_WALLET_ADDRESS_ACTION: agent.actions.find((action) => action.name === "GET_WALLET_ADDRESS_ACTION")!, }; // Start the MCP server startMcpServer(finalActions, agent, { name: "solana-agent", version: "0.0.1" }); ``` -------------------------------- ### Get a price inference from Allora Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/README.md Get the price for a given token and timeframe from Allora's API. ```APIDOC ## getPriceInference ### Description Get the price for a given token and timeframe from Allora's API. ### Method `agent.methods.getPriceInference(tokenSymbol, timeframe)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript const sol5mPrice = await agent.methods.getPriceInference("SOL", "5m"); console.log("5m price inference of SOL/USD:", sol5mPrice); ``` ### Response #### Success Response (200) - **priceInference** (number) - The inferred price for the token and timeframe. ``` -------------------------------- ### Install Vercel CLI Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/examples/embedded-wallets/crossmint-sak-v2/VERCEL_DEPLOYMENT.md Install the Vercel Command Line Interface globally if you plan to use the CLI for deployment. ```bash npm i -g vercel ``` -------------------------------- ### Initialize Node Project Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/@solana-agent-kit/adapter-mcp/README.md Initialize a new Node.js project using pnpm. ```bash pnpm init ``` -------------------------------- ### Install Blinks Plugin Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/plugins/blinks/blinks-plugin-intro.mdx Install the Blinks plugin along with the core Solana Agent Kit using npm. ```bash npm install solana-agent-kit @solana-agent-kit/plugin-blinks ``` -------------------------------- ### Get Voltr Vault Position Values Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/README.md Get the current position values and total value of assets in a Voltr vault. ```APIDOC ## voltrGetPositionValues ### Description Get the current position values and total value of assets in a Voltr vault. ### Method `agent.methods.voltrGetPositionValues(agent, vaultAddress)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript const values = await agent.methods.voltrGetPositionValues(agent, "7opUkqYtxmQRriZvwZkPcg6LqmGjAh1RSEsVrdsGDx5K") ``` ### Response #### Success Response (200) - **values** (object) - An object containing position values and total asset value. ``` -------------------------------- ### Example Usage: Register a Domain Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/packages/plugin-misc/README.md Demonstrates how to register a new .sol domain using the agent. ```APIDOC ## Register a Domain ```typescript const result = await agent.methods.registerDomain(agent, { name: "mydomain", spaceKB: 1, }); console.log("Domain Registration:", result); ``` ``` -------------------------------- ### Basic Feed Simulation Example Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/integrations/defi-integration/switchboard.mdx A straightforward example of simulating the SOL/USD price feed using the default Crossbar URL. ```typescript const value = await agent.methods.simulateSwitchboardFeed( FEEDS.SOL_USD ); console.log(`Current SOL price: $${value}`); ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/examples/embedded-wallets/react-native.mdx Copy example environment files and update them with your specific API keys and server information. ```bash # For client cp .env.local.example .env.local # For server cd server cp .env.example .env cd .. # For Expo configuration cp app.example.json app.json ``` -------------------------------- ### Initialize Solana Agent Kit V2 with KeypairWallet Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/MIGRATING.md Demonstrates V2 initialization using a KeypairWallet for signing transactions, allowing the use of a private key if preferred. ```typescript import {KeypairWallet, SolanaAgentKit } from 'solana-agent-kit' import TokenPlugin from '@solana-agent-kit/plugin-token' import { Keypair } from '@solana/web3.js' const keyPair = Keypair.fromSecretKey( bs58.decode(SOLANA_PRIVATE_KEY), ); // creates a class that implements the Wallet interface const wallet = new KeypairWallet(keyPair, RPC_URL); const agent = new SolanaAgentKit(wallet, RPC_URL, {}) .use(TokenPlugin) // use the plugin you want to use const tools = createVercelAITools(agent, agent.actions) ``` -------------------------------- ### Example Prompts for LangChain Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/integrations/defi-integration/switchboard.mdx Provides example natural language prompts that can be used with the LangChain tool to simulate various Switchboard feeds. ```APIDOC ## Example Prompts for LangChain These prompts can be used with the LangChain tool to trigger feed simulations. ### Feed Simulation Prompts - "Simulate the SOL/USD price feed" - "Get the current BTC price from Switchboard" - "Check the ETH/USD oracle feed" ``` -------------------------------- ### Custom Crossbar Instance Example Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/integrations/defi-integration/switchboard.mdx Example demonstrating how to use a custom Crossbar instance for feed simulation by providing an alternative URL. ```typescript const value = await agent.methods.simulateSwitchboardFeed( FEEDS.BTC_USD, "https://my-crossbar.example.com" ); ``` -------------------------------- ### Open Drizzle Studio Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/examples/misc/privy-server-wallet-agent/README.md Launches Drizzle Studio, a GUI for inspecting and managing your database. ```bash pnpm db:studio ``` -------------------------------- ### Example Natural Language Prompts for Orca Whirlpools Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/integrations/defi-integration/orca_whirlpool.mdx These are examples of natural language prompts that can be used to interact with Orca Whirlpools functionalities. ```text "Create a centered liquidity position with 5% range in SOL/USDC pool" "Open a single-sided USDC position 2.5% above current price" "Close my whirlpool position" "Check all my active liquidity positions" ``` -------------------------------- ### Example Natural Language Prompts for Token Launch Source: https://github.com/sendaifun/solana-agent-kit/blob/v2/docs/v2/integrations/defi-integration/launch_pumpfun.mdx These are examples of natural language prompts that can be used to initiate token launches on Pump.fun. ```text "Launch a new meme token called 'Rocket Dog' with the RDOG ticker" "Create a token on Pump.fun with 0.1 SOL initial liquidity" "Deploy a new token with Twitter and Telegram links" "Launch token with custom image and description on Pump.fun" ```