# PumpFun SDK
PumpFun SDK is a Python toolkit for interacting with the Pump.fun protocol on the Solana blockchain. This SDK provides modules for building transactions, monitoring on-chain events, decoding transactions with IDL support, and analyzing bonding curve states.
## Table of Contents
- [Features](#features)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Basic Usage](#basic-usage)
- [Token Operations](#token-operations)
- [User Operations](#user-operations)
- [Building Transactions](#building-transactions)
- [Monitoring Events](#monitoring-events)
- [Transaction Analysis](#transaction-analysis)
- [Examples](#examples)
- [Development](#development)
- [Contributing](#contributing)
- [License](#license)
## Features
- **Transaction Building:** Create buy and sell transactions with pre-defined instruction discriminators.
- **On-Chain Monitoring:** Subscribe to logs and account updates via websockets.
- **Transaction Analysis:** Decode and analyze transactions using a provided IDL.
- **Bonding Curve Analysis:** Parse on-chain bonding curve state and compute token prices.
- **Token Operations:** Retrieve token information, prices, holders, transactions, and liquidity.
- **User Operations:** Track user's created tokens, trading history, and liquidity positions.
## Installation
Install the SDK using pip:
```bash
pip install pumpfun-sdk
```
## Quick Start
### Basic Usage
This simple example demonstrates how to retrieve the bonding curve state for a token and monitor events for new token creations.
```python
#!/usr/bin/env python
"""
Basic Usage Example for pumpfun_sdk.
This script demonstrates how to:
- Retrieve and analyze the bonding curve state of a token.
- Monitor on-chain events for new token creations.
"""
import asyncio
from pumpfun_sdk.utils import subscribe_to_events, process_bonding_curve_state, monitor_new_tokens
async def example_check_token_status(mint_address: str):
try:
analysis = await process_bonding_curve_state(mint_address)
print("Token Analysis:")
for key, value in analysis.items():
print(f"{key}: {value}")
except Exception as e:
print(f"Error checking token status: {e}")
async def example_monitor_new_tokens():
async def token_handler(event_data):
if 'result' in event_data and 'value' in event_data['result']:
logs = event_data['result']['value'].get('logs', [])
if logs:
print("New Token Creation Detected!")
for log in logs:
print(log)
print("Starting token monitoring...")
await monitor_new_tokens(callback=token_handler)
async def main():
await example_check_token_status("YourTokenMintAddress")
await example_monitor_new_tokens()
if __name__ == "__main__":
asyncio.run(main())
```
### Token Operations
This example shows how to interact with token-related functionality.
```python
#!/usr/bin/env python
"""
Token Operations Example for pumpfun_sdk.
This script demonstrates how to:
- Get token information and metadata
- Get token price and market cap
- Get token holders
- Get token transactions
- Get token liquidity
"""
import asyncio
from pumpfun_sdk.usecases.token import (
get_token_info,
get_token_price,
get_token_holders,
get_token_transactions,
get_token_liquidity
)
async def example_token_operations(mint_address: str):
# Get comprehensive token information
token_info = await get_token_info(mint_address)
print("Token Info:", token_info)
# Get current token price
price = await get_token_price(mint_address)
print("Current Price:", price)
# Get token holders
holders = await get_token_holders(mint_address)
print("Token Holders:", holders)
# Get recent transactions
transactions = await get_token_transactions(mint_address, limit=10)
print("Recent Transactions:", transactions)
# Get liquidity information
liquidity = await get_token_liquidity(mint_address)
print("Liquidity Info:", liquidity)
async def main():
await example_token_operations("YourTokenMintAddress")
if __name__ == "__main__":
asyncio.run(main())
```
### User Operations
This example demonstrates how to track user activity and positions.
```python
#!/usr/bin/env python
"""
User Operations Example for pumpfun_sdk.
This script demonstrates how to:
- Get tokens created by a user
- Get tokens bought by a user
- Get tokens sold by a user
- Get user's liquidity positions
- Get user's transaction history
"""
import asyncio
from pumpfun_sdk.usecases.user import (
get_user_created_tokens,
get_user_bought_tokens,
get_user_sold_tokens,
get_user_liquidity,
get_user_transactions
)
async def example_user_operations(user_address: str):
# Get tokens created by the user
created_tokens = await get_user_created_tokens(user_address)
print("Created Tokens:", created_tokens)
# Get tokens bought by the user
bought_tokens = await get_user_bought_tokens(user_address)
print("Bought Tokens:", bought_tokens)
# Get tokens sold by the user
sold_tokens = await get_user_sold_tokens(user_address)
print("Sold Tokens:", sold_tokens)
# Get user's current liquidity positions
liquidity = await get_user_liquidity(user_address)
print("Liquidity Positions:", liquidity)
# Get user's recent transactions
transactions = await get_user_transactions(user_address, limit=10)
print("Recent Transactions:", transactions)
async def main():
await example_user_operations("YourWalletAddress")
if __name__ == "__main__":
asyncio.run(main())
```
### Building Transactions
This example shows how to build buy and sell transactions.
```python
#!/usr/bin/env python
"""
Trading Example for pumpfun_sdk.
This script demonstrates how to build buy and sell transactions for a Pump token.
"""
import asyncio
from solders.keypair import Keypair
from solders.pubkey import Pubkey
from pumpfun_sdk.transaction import build_buy_transaction, build_sell_transaction
async def example_transactions():
# Create a test keypair (replace with your actual keypair)
payer = Keypair()
# Example addresses (replace with actual addresses)
mint = Pubkey.new_unique()
bonding_curve = Pubkey.new_unique()
associated_bonding_curve = Pubkey.new_unique()
# Build a buy transaction (0.1 SOL amount)
print("=== Building Buy Transaction ===")
buy_tx = await build_buy_transaction(
payer=payer,
mint=mint,
bonding_curve=bonding_curve,
associated_bonding_curve=associated_bonding_curve,
amount=0.1
)
print("Buy Transaction:")
print(buy_tx)
# Build a sell transaction (100 tokens)
print("=== Building Sell Transaction ===")
sell_tx = await build_sell_transaction(
payer=payer,
mint=mint,
bonding_curve=bonding_curve,
associated_bonding_curve=associated_bonding_curve,
amount=100
)
print("Sell Transaction:")
print(sell_tx)
async def main():
await example_transactions()
if __name__ == "__main__":
asyncio.run(main())
```
### Monitoring Events
This example subscribes to on-chain log events for the Pump program.
```python
#!/usr/bin/env python
"""
Monitoring Example for pumpfun_sdk.
This script demonstrates how to subscribe to on-chain log events using
the subscribe_to_events function.
"""
import asyncio
from pumpfun_sdk import PUMP_PROGRAM
from pumpfun_sdk.utils import subscribe_to_events
async def monitor_program_activity():
async def activity_handler(event_data):
if 'result' in event_data and 'value' in event_data['result']:
logs = event_data['result']['value'].get('logs', [])
if logs:
print("Program Activity Detected!")
for log in logs:
print(log)
print(f"Starting monitoring for program: {PUMP_PROGRAM}")
await subscribe_to_events(
program_id=str(PUMP_PROGRAM),
callback=activity_handler,
subscription_type='logs'
)
if __name__ == "__main__":
asyncio.run(monitor_program_activity())
```
### Transaction Analysis
This example demonstrates how to decode a transaction using a provided IDL file. The SDK now uses `load_pump_idl` from `pumpfun_sdk.idl` for loading IDL definitions.
```python
#!/usr/bin/env python
"""
Transaction Analysis Example for pumpfun_sdk.
This script demonstrates how to:
- Load a raw transaction from a file.
- Decode the transaction using a provided IDL.
- Print the decoded instructions.
"""
import asyncio
from pumpfun_sdk.utils import decode_transaction_from_file
from pumpfun_sdk.idl import load_pump_idl
async def analyze_transaction():
# Replace these with actual file paths
tx_file = "path/to/transaction.json"
idl_file = "path/to/idl.json"
print("=== Analyzing Transaction ===")
try:
# This function uses the custom IDL file if provided, otherwise falls back to the built-in Pump Fun IDL.
await decode_transaction_from_file(tx_file, idl_file)
except Exception as e:
print(f"Error analyzing transaction: {e}")
if __name__ == "__main__":
asyncio.run(analyze_transaction())
```
## Examples
Detailed examples can be found in the `examples/` directory:
- **basic_usage.py:** Basic utilization including bonding curve analysis and event monitoring.
- **token_operations.py:** Working with token information and analysis.
- **user_operations.py:** Tracking user activity and positions.
- **monitoring_example.py:** Subscribing to on-chain log events.
- **trading_example.py:** Building buy and sell transactions.
- **transaction_analysis.py:** Decoding transaction data using IDL support.
## Development
### Setup
1. **Clone the Repository:**
```bash
git clone https://github.com/gendev1/pumpfun-sdk.git
cd pumpfun-sdk
```
2. **Install Dependencies:**
```bash
poetry install
```
### Testing
Run the test suite and check coverage:
```bash
poetry run pytest --cov=pumpfun_sdk --cov-report=term-missing
```
## Contributing
Contributions are welcome! To contribute:
1. Fork the repository.
2. Create your feature branch:
```bash
git checkout -b feature/your-feature
```
3. Commit your changes:
```bash
git commit -m 'Add feature'
```
4. Push your branch:
```bash
git push origin feature/your-feature
```
5. Open a Pull Request.
## License
This project is licensed under the [MIT License](LICENSE).
Raw data
{
"_id": null,
"home_page": "https://github.com/gendev1/pumpfun-sdk",
"name": "pumpfun-sdk",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8",
"maintainer_email": null,
"keywords": "solana, blockchain, pump.fun, trading, sdk",
"author": "Your Name",
"author_email": "your.email@example.com",
"download_url": "https://files.pythonhosted.org/packages/7c/b6/3b2684f86b6fdabaec44fe2a017463c9e35f5e28decbaaeacf8ae6591af6/pumpfun_sdk-0.1.0.tar.gz",
"platform": null,
"description": "# PumpFun SDK\n\nPumpFun SDK is a Python toolkit for interacting with the Pump.fun protocol on the Solana blockchain. This SDK provides modules for building transactions, monitoring on-chain events, decoding transactions with IDL support, and analyzing bonding curve states.\n\n## Table of Contents\n\n- [Features](#features)\n- [Installation](#installation)\n- [Quick Start](#quick-start)\n - [Basic Usage](#basic-usage)\n - [Token Operations](#token-operations)\n - [User Operations](#user-operations)\n - [Building Transactions](#building-transactions)\n - [Monitoring Events](#monitoring-events)\n - [Transaction Analysis](#transaction-analysis)\n- [Examples](#examples)\n- [Development](#development)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Features\n\n- **Transaction Building:** Create buy and sell transactions with pre-defined instruction discriminators.\n- **On-Chain Monitoring:** Subscribe to logs and account updates via websockets.\n- **Transaction Analysis:** Decode and analyze transactions using a provided IDL.\n- **Bonding Curve Analysis:** Parse on-chain bonding curve state and compute token prices.\n- **Token Operations:** Retrieve token information, prices, holders, transactions, and liquidity.\n- **User Operations:** Track user's created tokens, trading history, and liquidity positions.\n\n## Installation\n\nInstall the SDK using pip:\n\n```bash\npip install pumpfun-sdk\n```\n\n## Quick Start\n\n### Basic Usage\n\nThis simple example demonstrates how to retrieve the bonding curve state for a token and monitor events for new token creations.\n\n```python\n#!/usr/bin/env python\n\"\"\"\nBasic Usage Example for pumpfun_sdk.\n\nThis script demonstrates how to:\n- Retrieve and analyze the bonding curve state of a token.\n- Monitor on-chain events for new token creations.\n\"\"\"\n\nimport asyncio\nfrom pumpfun_sdk.utils import subscribe_to_events, process_bonding_curve_state, monitor_new_tokens\n\nasync def example_check_token_status(mint_address: str):\n try:\n analysis = await process_bonding_curve_state(mint_address)\n print(\"Token Analysis:\")\n for key, value in analysis.items():\n print(f\"{key}: {value}\")\n except Exception as e:\n print(f\"Error checking token status: {e}\")\n\nasync def example_monitor_new_tokens():\n async def token_handler(event_data):\n if 'result' in event_data and 'value' in event_data['result']:\n logs = event_data['result']['value'].get('logs', [])\n if logs:\n print(\"New Token Creation Detected!\")\n for log in logs:\n print(log)\n print(\"Starting token monitoring...\")\n await monitor_new_tokens(callback=token_handler)\n\nasync def main():\n await example_check_token_status(\"YourTokenMintAddress\")\n await example_monitor_new_tokens()\n\nif __name__ == \"__main__\":\n asyncio.run(main())\n```\n\n### Token Operations\n\nThis example shows how to interact with token-related functionality.\n\n```python\n#!/usr/bin/env python\n\"\"\"\nToken Operations Example for pumpfun_sdk.\n\nThis script demonstrates how to:\n- Get token information and metadata\n- Get token price and market cap\n- Get token holders\n- Get token transactions\n- Get token liquidity\n\"\"\"\n\nimport asyncio\nfrom pumpfun_sdk.usecases.token import (\n get_token_info,\n get_token_price,\n get_token_holders,\n get_token_transactions,\n get_token_liquidity\n)\n\nasync def example_token_operations(mint_address: str):\n # Get comprehensive token information\n token_info = await get_token_info(mint_address)\n print(\"Token Info:\", token_info)\n\n # Get current token price\n price = await get_token_price(mint_address)\n print(\"Current Price:\", price)\n\n # Get token holders\n holders = await get_token_holders(mint_address)\n print(\"Token Holders:\", holders)\n\n # Get recent transactions\n transactions = await get_token_transactions(mint_address, limit=10)\n print(\"Recent Transactions:\", transactions)\n\n # Get liquidity information\n liquidity = await get_token_liquidity(mint_address)\n print(\"Liquidity Info:\", liquidity)\n\nasync def main():\n await example_token_operations(\"YourTokenMintAddress\")\n\nif __name__ == \"__main__\":\n asyncio.run(main())\n```\n\n### User Operations\n\nThis example demonstrates how to track user activity and positions.\n\n```python\n#!/usr/bin/env python\n\"\"\"\nUser Operations Example for pumpfun_sdk.\n\nThis script demonstrates how to:\n- Get tokens created by a user\n- Get tokens bought by a user\n- Get tokens sold by a user\n- Get user's liquidity positions\n- Get user's transaction history\n\"\"\"\n\nimport asyncio\nfrom pumpfun_sdk.usecases.user import (\n get_user_created_tokens,\n get_user_bought_tokens,\n get_user_sold_tokens,\n get_user_liquidity,\n get_user_transactions\n)\n\nasync def example_user_operations(user_address: str):\n # Get tokens created by the user\n created_tokens = await get_user_created_tokens(user_address)\n print(\"Created Tokens:\", created_tokens)\n\n # Get tokens bought by the user\n bought_tokens = await get_user_bought_tokens(user_address)\n print(\"Bought Tokens:\", bought_tokens)\n\n # Get tokens sold by the user\n sold_tokens = await get_user_sold_tokens(user_address)\n print(\"Sold Tokens:\", sold_tokens)\n\n # Get user's current liquidity positions\n liquidity = await get_user_liquidity(user_address)\n print(\"Liquidity Positions:\", liquidity)\n\n # Get user's recent transactions\n transactions = await get_user_transactions(user_address, limit=10)\n print(\"Recent Transactions:\", transactions)\n\nasync def main():\n await example_user_operations(\"YourWalletAddress\")\n\nif __name__ == \"__main__\":\n asyncio.run(main())\n```\n\n### Building Transactions\n\nThis example shows how to build buy and sell transactions.\n\n```python\n#!/usr/bin/env python\n\"\"\"\nTrading Example for pumpfun_sdk.\n\nThis script demonstrates how to build buy and sell transactions for a Pump token.\n\"\"\"\n\nimport asyncio\nfrom solders.keypair import Keypair\nfrom solders.pubkey import Pubkey\nfrom pumpfun_sdk.transaction import build_buy_transaction, build_sell_transaction\n\nasync def example_transactions():\n # Create a test keypair (replace with your actual keypair)\n payer = Keypair()\n\n # Example addresses (replace with actual addresses)\n mint = Pubkey.new_unique()\n bonding_curve = Pubkey.new_unique()\n associated_bonding_curve = Pubkey.new_unique()\n\n # Build a buy transaction (0.1 SOL amount)\n print(\"=== Building Buy Transaction ===\")\n buy_tx = await build_buy_transaction(\n payer=payer,\n mint=mint,\n bonding_curve=bonding_curve,\n associated_bonding_curve=associated_bonding_curve,\n amount=0.1\n )\n print(\"Buy Transaction:\")\n print(buy_tx)\n\n # Build a sell transaction (100 tokens)\n print(\"=== Building Sell Transaction ===\")\n sell_tx = await build_sell_transaction(\n payer=payer,\n mint=mint,\n bonding_curve=bonding_curve,\n associated_bonding_curve=associated_bonding_curve,\n amount=100\n )\n print(\"Sell Transaction:\")\n print(sell_tx)\n\nasync def main():\n await example_transactions()\n\nif __name__ == \"__main__\":\n asyncio.run(main())\n```\n\n### Monitoring Events\n\nThis example subscribes to on-chain log events for the Pump program.\n\n```python\n#!/usr/bin/env python\n\"\"\"\nMonitoring Example for pumpfun_sdk.\n\nThis script demonstrates how to subscribe to on-chain log events using\nthe subscribe_to_events function.\n\"\"\"\n\nimport asyncio\nfrom pumpfun_sdk import PUMP_PROGRAM\nfrom pumpfun_sdk.utils import subscribe_to_events\n\nasync def monitor_program_activity():\n async def activity_handler(event_data):\n if 'result' in event_data and 'value' in event_data['result']:\n logs = event_data['result']['value'].get('logs', [])\n if logs:\n print(\"Program Activity Detected!\")\n for log in logs:\n print(log)\n print(f\"Starting monitoring for program: {PUMP_PROGRAM}\")\n await subscribe_to_events(\n program_id=str(PUMP_PROGRAM),\n callback=activity_handler,\n subscription_type='logs'\n )\n\nif __name__ == \"__main__\":\n asyncio.run(monitor_program_activity())\n```\n\n### Transaction Analysis\n\nThis example demonstrates how to decode a transaction using a provided IDL file. The SDK now uses `load_pump_idl` from `pumpfun_sdk.idl` for loading IDL definitions.\n\n```python\n#!/usr/bin/env python\n\"\"\"\nTransaction Analysis Example for pumpfun_sdk.\n\nThis script demonstrates how to:\n- Load a raw transaction from a file.\n- Decode the transaction using a provided IDL.\n- Print the decoded instructions.\n\"\"\"\n\nimport asyncio\nfrom pumpfun_sdk.utils import decode_transaction_from_file\nfrom pumpfun_sdk.idl import load_pump_idl\n\nasync def analyze_transaction():\n # Replace these with actual file paths\n tx_file = \"path/to/transaction.json\"\n idl_file = \"path/to/idl.json\"\n\n print(\"=== Analyzing Transaction ===\")\n try:\n # This function uses the custom IDL file if provided, otherwise falls back to the built-in Pump Fun IDL.\n await decode_transaction_from_file(tx_file, idl_file)\n except Exception as e:\n print(f\"Error analyzing transaction: {e}\")\n\nif __name__ == \"__main__\":\n asyncio.run(analyze_transaction())\n```\n\n## Examples\n\nDetailed examples can be found in the `examples/` directory:\n\n- **basic_usage.py:** Basic utilization including bonding curve analysis and event monitoring.\n- **token_operations.py:** Working with token information and analysis.\n- **user_operations.py:** Tracking user activity and positions.\n- **monitoring_example.py:** Subscribing to on-chain log events.\n- **trading_example.py:** Building buy and sell transactions.\n- **transaction_analysis.py:** Decoding transaction data using IDL support.\n\n## Development\n\n### Setup\n\n1. **Clone the Repository:**\n\n ```bash\n git clone https://github.com/gendev1/pumpfun-sdk.git\n cd pumpfun-sdk\n ```\n\n2. **Install Dependencies:**\n\n ```bash\n poetry install\n ```\n\n### Testing\n\nRun the test suite and check coverage:\n\n```bash\npoetry run pytest --cov=pumpfun_sdk --cov-report=term-missing\n```\n\n## Contributing\n\nContributions are welcome! To contribute:\n\n1. Fork the repository.\n2. Create your feature branch:\n ```bash\n git checkout -b feature/your-feature\n ```\n3. Commit your changes:\n ```bash\n git commit -m 'Add feature'\n ```\n4. Push your branch:\n ```bash\n git push origin feature/your-feature\n ```\n5. Open a Pull Request.\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python SDK for interacting with the Pump.fun protocol on Solana blockchain",
"version": "0.1.0",
"project_urls": {
"Documentation": "https://github.com/gendev1/pumpfun-sdk#readme",
"Homepage": "https://github.com/gendev1/pumpfun-sdk",
"Repository": "https://github.com/gendev1/pumpfun-sdk"
},
"split_keywords": [
"solana",
" blockchain",
" pump.fun",
" trading",
" sdk"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a50ee8c66034f10128155b2656228162717f557cc97a5078f8e02688f359fddc",
"md5": "5d37324ba80eec4ea7b92cf2e70b620b",
"sha256": "af223e2165c9045435383c45db637c60522cb36411725006651c1cce61bedddf"
},
"downloads": -1,
"filename": "pumpfun_sdk-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "5d37324ba80eec4ea7b92cf2e70b620b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8",
"size": 18634,
"upload_time": "2025-02-03T00:09:02",
"upload_time_iso_8601": "2025-02-03T00:09:02.973644Z",
"url": "https://files.pythonhosted.org/packages/a5/0e/e8c66034f10128155b2656228162717f557cc97a5078f8e02688f359fddc/pumpfun_sdk-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7cb63b2684f86b6fdabaec44fe2a017463c9e35f5e28decbaaeacf8ae6591af6",
"md5": "51e20d4c4cd3900dad5a6679505afb72",
"sha256": "46ad5db1e278412444dacc919f756f1b02d4bad7517b9a0c3f6d415723f2c657"
},
"downloads": -1,
"filename": "pumpfun_sdk-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "51e20d4c4cd3900dad5a6679505afb72",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8",
"size": 17040,
"upload_time": "2025-02-03T00:09:04",
"upload_time_iso_8601": "2025-02-03T00:09:04.244328Z",
"url": "https://files.pythonhosted.org/packages/7c/b6/3b2684f86b6fdabaec44fe2a017463c9e35f5e28decbaaeacf8ae6591af6/pumpfun_sdk-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-03 00:09:04",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "gendev1",
"github_project": "pumpfun-sdk",
"github_not_found": true,
"lcname": "pumpfun-sdk"
}