Skip to main content

A Python toolkit for Solana agents

Project description

Solana Agent Kit

A powerful toolkit for interacting with the Solana blockchain, providing easy-to-use functions for token operations, and trading. Now integrated with LangChain for enhanced functionality.

Features

  • 🪙 Token Operations

    • Transfer SOL and SPL tokens
    • Check token balances
    • Stake SOL
  • 💱 Trading

    • Integrated Jupiter Exchange support
    • Token swaps with customizable slippage
    • Direct routing options
  • 🏦 Yield Farming

    • Lend idle assets to earn interest with Lulo
  • 🔗 LangChain Integration

    • Utilize LangChain tools for enhanced blockchain interactions
    • Access a suite of tools for balance checks, transfers, token deployments, and more

Installation

pip install agentipy

Quick Start

from agentipy import SolanaAgentKit, create_solana_tools

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

# Create LangChain tools
tools = create_solana_tools(agent)

Usage Examples

Fetch price of a token

from agentipy import SolanaAgentKit

async def main():
agent = SolanaAgentKit(
    "your-wallet-private-key-as-base58",
    "https://api.mainnet-beta.solana.com",
    "your-openai-api-key"
)

    # Get balance
    balance =  await agent.fetch_price("FKMKctiJnbZKL16pCmR7ig6bvjcMJffuUMjB97YD7LJs")
    print(f"Price: {balance} SOL")

# Run the async function
import asyncio
asyncio.run(main())

Swap Tokens

from agentipy import SolanaAgentKit

from solders.pubkey import Pubkey

async def main():
agent = SolanaAgentKit(
    "your-wallet-private-key-as-base58",
    "https://api.mainnet-beta.solana.com",
    "your-openai-api-key"
)

signature = await agent.trade(
    agent,
    output_mint=Pubkey.from_string("target-token-mint"),
    input_amount=100,  # amount
    input_mint=Pubkey.from_string("source-token-mint"),
    slippage_bps=300  # 3% slippage
)

import asyncio
asyncio.run(main())

Lend Tokens

from agentipy import SolanaAgentKit

from solders.pubkey import Pubkey

async def main():
agent = SolanaAgentKit(
    "your-wallet-private-key-as-base58",
    "https://api.mainnet-beta.solana.com",
    "your-openai-api-key"
)
signature = await agent.lend_assets(
    amount=100  # amount
)

import asyncio
asyncio.run(main())

Stake SOL

from agentipy import SolanaAgentKit

from solders.pubkey import Pubkey

async def main():
agent = SolanaAgentKit(
    "your-wallet-private-key-as-base58",
    "https://api.mainnet-beta.solana.com",
    "your-openai-api-key"
)

signature = await agent.stake(
    amount=1  # amount in SOL
)

import asyncio
asyncio.run(main())

API Reference

Core Functions

transfer(agent, to, amount, mint?)

Transfer SOL or SPL tokens to a recipient.

trade(agent, output_mint, input_amount, input_mint?, slippage_bps?)

Swap tokens using Jupiter Exchange integration.

get_balance(agent, token_address)

Check SOL or token balance for the agent's wallet.

lend_asset(agent, asset_mint, amount)

Lend idle assets to earn interest with Lulo.

stake(agent, amount)

Stake SOL with Jupiter to earn rewards.

Dependencies

The toolkit relies on several key Solana and Metaplex libraries:

  • solana-py
  • spl-token-py

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

ISC 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.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agentipy-1.1.6.tar.gz (19.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agentipy-1.1.6-py3-none-any.whl (25.8 kB view details)

Uploaded Python 3

File details

Details for the file agentipy-1.1.6.tar.gz.

File metadata

  • Download URL: agentipy-1.1.6.tar.gz
  • Upload date:
  • Size: 19.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for agentipy-1.1.6.tar.gz
Algorithm Hash digest
SHA256 8abd3c19f7d206d9b65ab6c3c5bba105316c0f09adcf85075413dd9c950a6740
MD5 920ccf4a1a1e8551f92506016ad59c9c
BLAKE2b-256 04346d87132c2e6788471046314da485112317478e7c436885f249458c3024bf

See more details on using hashes here.

File details

Details for the file agentipy-1.1.6-py3-none-any.whl.

File metadata

  • Download URL: agentipy-1.1.6-py3-none-any.whl
  • Upload date:
  • Size: 25.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for agentipy-1.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 a31060bec8c63e2073a923c01bd284ebbc976619271444e318ed598e704d8495
MD5 db003d827e4ebed9c48552267cac7702
BLAKE2b-256 5f141b36ec456a405a7a95890b4b127371c2f0ca08eb67d15a4104b3bab8aed5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page