Skip to main content

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:

  1. SECRET_WORDS: Your wallet's recovery phrase
  2. HELIUS_API_KEY: Your Helius API key (https://helius.dev/)
  3. 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 jupswapper 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 jupswapper 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


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.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

jupswapper-0.1.1-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file jupswapper-0.1.1.tar.gz.

File metadata

  • Download URL: jupswapper-0.1.1.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

Hashes for jupswapper-0.1.1.tar.gz
Algorithm Hash digest
SHA256 eeb671cef87a2438e090c93172ebe3c7619fd4c54785cdc71b45fbf6f734750d
MD5 3a1da3a73c095569cd5196e79ee453a7
BLAKE2b-256 c4cd9342700935a79d750504f97bbd0567974923334e5268ecd8df16cb163b33

See more details on using hashes here.

File details

Details for the file jupswapper-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: jupswapper-0.1.1-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

Hashes for jupswapper-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d0d505af4a87edb391618767fc8104deceed52e976a56514fdfb2bf1498ba965
MD5 e5fae84955232bb221e1e2065ec9d8e5
BLAKE2b-256 5bfc5c2a6e0ac7e6f18eab66bfac89ca29b09cd2a3cfffac9afa3abec6b99814

See more details on using hashes here.

Supported by

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