A Python package for token swapping and wallet interactions on Solana using Jupiter Aggregator
Project description
jupswapper
A Python package for token swapping and wallet interactions on Solana using Jupiter Aggregator and Helius RPC endpoints.
Key Features
- 🔄 High-level interface for token swaps
- 💰 Wallet balance checking with USD valuations
- 💸 SOL balance
- 🛡️ Built-in retry mechanisms for robust transaction handling
- 📊 Automatic slippage protection from Jupiter Aggregator
Prerequisites
- Python 3.12+
- Solana wallet with some SOL for transaction fees
- Helius API key (for RPC endpoints and transaction tracking)
Installation
Install jupswapper
using pip:
pip install jupswapper
Configuration
Set the following environment variables:
SECRET_WORDS
: Your wallet's recovery phraseHELIUS_API_KEY
: Your Helius API key (https://helius.dev/)DERIVE_PATH
: Your wallet's derivation path (default: "m/44'/501'/0'")
We recommend using 1password-cli to inject these variables into your environment at runtime.
brew install 1password-cli
Usage Examples
See examples/
for the following scripts.
Performing a Token Swap
from jupswap import Swap, SOL_MINT, BONK_MINT, try_swap
# Swap 0.01 SOL to BONK
swap = Swap(from_mint=SOL_MINT, to_mint=BONK_MINT, amount=0.01)
transaction_response = try_swap(swap)
print(transaction_response)
Checking Wallet Balance
from jupswap import get_token_values_for_wallet, get_public_key_as_str, get_sol_balance
wallet_address = get_public_key_as_str()
token_values = get_token_values_for_wallet(wallet_address)
# Print token balances with USD values
for token in token_values:
print(f"{token.symbol}: {token.amount_int} (${token.usd_value})")
# Get SOL balance
sol_balance = get_sol_balance(wallet_address)
print(f"SOL balance: {sol_balance}")
Environment Variables
MAX_BPS
: Maximum basis points for slippage (default: 300)MAX_RETRIES
: Maximum retry attempts for transactions (default: 5)AWAIT_CONFIRMATION_MAX_RETRIES
: Maximum retries for transaction confirmation (default: 14)AWAIT_CONFIRMATION_RETRY_DELAY
: Delay between confirmation retries (default: 2 seconds)
Disclaimer
Use at your own risk. Always test with small amounts.
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
jupswapper-0.1.0.tar.gz
(6.1 kB
view details)
Built Distribution
File details
Details for the file jupswapper-0.1.0.tar.gz
.
File metadata
- Download URL: jupswapper-0.1.0.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19f627ff889159d964dda54cf96ccdc867ef4a98a3b05cad0913b0197448d2f3 |
|
MD5 | f789fd1577a1ad9a0e474e6bd9d2e0d4 |
|
BLAKE2b-256 | 91ad7f49ad9f87b31d7552b9cd0331d572e4fafc95c660eca405ff68429dcc64 |
File details
Details for the file jupswapper-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: jupswapper-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c88233e4c16d6d662691e4ee9fb748282b435b889afa0c2a94855270235fd673 |
|
MD5 | 8df7d166955422df84ee595275b4aab8 |
|
BLAKE2b-256 | a05bdf6a361a1248abb2d6e0b741b1f251447ada29cf7b18afd185b52a8b184e |