aryan da09193d9d feat: vercel-ai-sdk (#67)
# Pull Request Description

## Related Issue
Fixes #54 

## Changes Made
This PR adds the following changes:
<!-- List the key changes made in this PR -->
- Adds support for the Vercel AI SDK.
- Adds tests showcasing that the feature addition works.
  
## Implementation Details
<!-- Provide technical details about the implementation -->
- In order to add support for the SDK I installed all required
dependencies such as `ai, @ai-sdk/openai, and zod`
- The overall integration was simple, however, quite tedious as it
required a lot of conversions from the existing langchain integration

## Transaction executed by agent 
<!-- If applicable, provide example usage, transactions, or screenshots
-->
Example transaction: 
- TX link:
[4W5LFS9GnxeSffD1S2teUhg5e6VgL6P2DAQ4LQYqygk2nQJJLTtyi38zj5FaM2RiZe53ZmhRjuVqp47fXgnQwtva](https://solscan.io/tx/4W5LFS9GnxeSffD1S2teUhg5e6VgL6P2DAQ4LQYqygk2nQJJLTtyi38zj5FaM2RiZe53ZmhRjuVqp47fXgnQwtva)
- TX link:
[3oqHWwxUV6iz1ASxSyUikTPwA5MNySiUeBxzb5r2craoxEQXWdtXwtRkLnuDmYECvZZHZe6KvP7kTrydDrckGNXf](https://solscan.io/tx/3oqHWwxUV6iz1ASxSyUikTPwA5MNySiUeBxzb5r2craoxEQXWdtXwtRkLnuDmYECvZZHZe6KvP7kTrydDrckGNXf)
- TX link:
[51Wb8aQz1HE6X9pXmR9QJDoeEbV8chv8uEjzKdyTJfskngNiJj32VeEvRRHD8JKEXR6ydqqbCvfyDygWmdqQHtDx](https://solscan.io/tx/51Wb8aQz1HE6X9pXmR9QJDoeEbV8chv8uEjzKdyTJfskngNiJj32VeEvRRHD8JKEXR6ydqqbCvfyDygWmdqQHtDx)
- TX link:
[5yu133Sj2vztDHa43f7VASkibziDwSrYiZUuv1S9E6ov3S6N1bXyUa7MXDtV2E4XJLK4SfAepRC3fZqMEa4SnNyj](https://solscan.io/tx/5yu133Sj2vztDHa43f7VASkibziDwSrYiZUuv1S9E6ov3S6N1bXyUa7MXDtV2E4XJLK4SfAepRC3fZqMEa4SnNyj)
- Screenshot:
![Screenshot 2024-12-26 at 16 14
54](https://github.com/user-attachments/assets/69bbcdba-0c82-4af2-874d-c07493677124)


## Prompt Used
<!-- If relevant, include the prompt or configuration used -->
- No particular prompt was used. I ran `pnpm run test:vercel-ai`, chose
the autonomous option and let it do it's thing.

## Additional Notes
<!-- Any additional information that reviewers should know -->
The code `_call`/`execute` can be made reusable in case of any future
agent/platform integrations. This could be made into another bounty as
it will be quite tedious as well and type standards would need to be set
for maximum compatibility and least overhead down the line.

## Checklist
- [x] I have tested these changes locally
- [x] I have updated the documentation
- [x] I have added a transaction link
- [x] I have added the prompt used to test it
2025-01-03 23:16:38 +05:30
2024-12-25 19:42:38 +05:30
2025-01-01 05:12:23 +01:00
2025-01-03 18:22:32 +01:00
2025-01-03 18:22:32 +01:00
2024-12-31 16:28:23 +05:30
2024-12-30 03:26:26 +05:30
2024-11-17 21:39:36 +07:00
2024-12-25 17:08:17 +05:30
2024-12-25 17:08:17 +05:30
2024-12-24 16:41:38 +05:30
2024-12-21 00:03:22 +05:30
2024-12-25 17:08:17 +05:30
2025-01-03 18:22:32 +01:00
2024-12-30 06:32:44 +05:30
2024-12-26 16:29:03 +01:00

Solana Agent Kit

Solana Agent Kit Cover 1 (3)

NPM Downloads GitHub forks GitHub License

An open-source toolkit for connecting AI agents to Solana protocols. Now, any agent, using any model can autonomously perform 15+ Solana actions:

  • Trade tokens
  • Launch new tokens
  • Lend assets
  • Send compressed airdrops
  • Execute blinks
  • Launch tokens on AMMs
  • And more...

Anyone - whether an SF-based AI researcher or a crypto-native builder - can bring their AI agents trained with any model and seamlessly integrate with Solana.

Run on Repl.it

Replit template created by Arpit Singh

🔧 Core Blockchain Features

  • Token Operations

    • Deploy SPL tokens by Metaplex
    • Transfer assets
    • Balance checks
    • Stake SOL
    • Zk compressed Airdrop by Light Protocol and Helius
  • NFT Management via Metaplex

    • Collection deployment
    • NFT minting
    • Metadata management
    • Royalty configuration
  • DeFi Integration

    • Jupiter Exchange swaps
    • Launch on Pump via PumpPortal
    • Raydium pool creation (CPMM, CLMM, AMMv4)
    • Orca Whirlpool integration
    • Manifest market creation, and limit orders
    • Meteora Dynamic AMM, DLMM Pool, and Alpha Vault
    • Openbook market creation
    • Register and Resolve SNS
    • Jito Bundles
    • Pyth Price feeds for fetching Asset Prices
    • Register/resolve Alldomains
  • Solana Blinks

    • Lending by Lulo (Best APR for USDC)
    • Send Arcade Games
    • JupSOL staking
  • Non-Financial Actions

    • Gib Work for registering bounties

🤖 AI Integration Features

  • LangChain Integration

    • Ready-to-use LangChain tools for blockchain operations
    • Autonomous agent support with React framework
    • Memory management for persistent interactions
    • Streaming responses for real-time feedback
  • Vercel AI SDK Integration

    • Vercel AI SDK for AI agent integration
    • Framework agnostic support
    • Quick and easy toolkit setup
  • Autonomous Modes

    • Interactive chat mode for guided operations
    • Autonomous mode for independent agent actions
    • Configurable action intervals
    • Built-in error handling and recovery
  • AI Tools

    • DALL-E integration for NFT artwork generation
    • Natural language processing for blockchain commands
    • Price feed integration for market analysis
    • Automated decision-making capabilities

📦 Installation

npm install solana-agent-kit

Quick Start

import { SolanaAgentKit, createSolanaTools } from "solana-agent-kit";

// Initialize with private key and optional RPC URL
const agent = new SolanaAgentKit(
  "your-wallet-private-key-as-base58",
  "https://api.mainnet-beta.solana.com",
  "your-openai-api-key"
);

// Create LangChain tools
const tools = createSolanaTools(agent);

Usage Examples

Deploy a New Token

const result = await agent.deployToken(
  "my ai token", // name
  "uri", // uri
  "token", // symbol
  9, // decimals
  1000000 // initial supply
);

console.log("Token Mint Address:", result.mint.toString());

Create NFT Collection

const collection = await agent.deployCollection({
  name: "My NFT Collection",
  uri: "https://arweave.net/metadata.json",
  royaltyBasisPoints: 500, // 5%
  creators: [
    {
      address: "creator-wallet-address",
      percentage: 100,
    },
  ],
});

Swap Tokens

import { PublicKey } from "@solana/web3.js";

const signature = await agent.trade(
  new PublicKey("target-token-mint"),
  100, // amount
  new PublicKey("source-token-mint"),
  300 // 3% slippage
);

Lend Tokens

import { PublicKey } from "@solana/web3.js";

const signature = await agent.lendAssets(
  100 // amount of USDC to lend
);

Stake SOL

const signature = await agent.stake(
  1 // amount in SOL to stake
);

Send an SPL Token Airdrop via ZK Compression

import { PublicKey } from "@solana/web3.js";

(async () => {
  console.log(
    "~Airdrop cost estimate:",
    getAirdropCostEstimate(
      1000, // recipients
      30_000 // priority fee in lamports
    )
  );

  const signature = await agent.sendCompressedAirdrop(
    new PublicKey("JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN"), // mint
    42, // amount per recipient
    [
      new PublicKey("1nc1nerator11111111111111111111111111111111"),
      // ... add more recipients
    ],
    30_000 // priority fee in lamports
  );
})();

Fetch Price Data from Pyth


const price = await agent.pythFetchPrice(
  "0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43"
);

console.log("Price in BTC/USD:", price);

Examples

LangGraph Multi-Agent System

The repository includes an advanced example of building a multi-agent system using LangGraph and Solana Agent Kit. Located in examples/agent-kit-langgraph, this example demonstrates:

  • Multi-agent architecture using LangGraph's StateGraph
  • Specialized agents for different tasks:
    • General purpose agent for basic queries
    • Transfer/Swap agent for transaction operations
    • Read agent for blockchain data queries
    • Manager agent for routing and orchestration
  • Fully typed TypeScript implementation
  • Environment-based configuration

Check out the LangGraph example for a complete implementation of an advanced Solana agent system.

Dependencies

The toolkit relies on several key Solana and Metaplex libraries:

  • @solana/web3.js
  • @solana/spl-token
  • @metaplex-foundation/mpl-token-metadata
  • @metaplex-foundation/mpl-core
  • @metaplex-foundation/umi
  • @lightprotocol/compressed-token
  • @lightprotocol/stateless.js
  • @pythnetwork/price-service-client

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. Refer to CONTRIBUTING.md for detailed guidelines on how to contribute to this project.

Contributors

Star History

Star History Chart

License

Apache-2 License

Security

This toolkit handles private keys and transactions. Always ensure you're using it in a secure environment and never share your private keys.

Description
connect any ai agents to solana protocols
Readme Apache-2.0 Cite this repository 3.5 MiB
Languages
TypeScript 100%