Skip to main content

PumpSwap

PumpSwap is a Python module for interacting with Solana's Pump.fun tokens. Automatically build instructions for your transaction, or simply use built-in functions to make Pump.fun swaps.

More information here: https://github.com/FLOCK4H/pump_swap

Usage

Example script:


from pump_swap import PumpSwap, usd_to_lamports, lamports_to_tokens, usd_to_microlamports
from decimal import Decimal
import asyncio, aiohttp, json

PRIV_KEY = ""
WALLET = ""
STAKED_API = "" # e.g. staked helius

# Create a PumpSwap object
async def main():
    session = aiohttp.ClientSession()
    priv_key = PRIV_KEY # str
    rpc_endpoint = STAKED_API # str
    debug = True

    pump_swap = PumpSwap(session=session, priv_key=priv_key, rpc_endpoint=rpc_endpoint, debug=debug)
    solana_price = pump_swap.get_solana_price_usd()
    solana_price = Decimal(solana_price)

    mint_address = "2MWw9bXmevKxuof49uRFb59dAaFAtAydsrXzR4jNpump"
    bonding_curve, ass_bonding_curve = await pump_swap.get_bonding_curve_pda(mint_address)
    token_price = Decimal("0.0000000280") # Token price can be calculated using vsr/vtr formula.

    amount = input("Enter the amount of USD to spend: ")
    sol_to_spend = await usd_to_lamports(int(amount.strip()), solana_price)
    sol_to_tokens = await lamports_to_tokens(sol_to_spend, token_price)

    should_simulate = False
    fee = await usd_to_microlamports(0.1, solana_price, 50_000) # 0.1$ per 50k compute units

    buy_sig = await pump_swap.pump_buy(
        mint_address=mint_address,
        bonding_curve_pda=bonding_curve,
        sol_amount=sol_to_spend,
        token_amount=sol_to_tokens,
        sim=should_simulate,
        priority_micro_lamports=fee,
        slippage=1.5 # e.g. 50% slippage
    )

    # Here we get signature of the transaction
    result_json = buy_sig.to_json()
    transaction_id = json.loads(result_json).get('result')
    print("Buy: ", transaction_id)
    # Then we can use it to verify if we got success
    verify = await pump_swap.getTransaction(transaction_id, session)
    print(f"{json.dumps(verify, indent=2)}")

    await asyncio.sleep(5)

    sell_sig = await pump_swap.pump_sell(
        mint_address=mint_address,
        bonding_curve_pda=bonding_curve,
        token_amount=sol_to_tokens,
        sim=should_simulate,
        priority_micro_lamports=fee,
    )

    result_json = sell_sig.to_json()
    transaction_id = json.loads(result_json).get('result')
    print("Sell: ", transaction_id)

    verify = await pump_swap.getTransaction(transaction_id, session)
    print(f"{json.dumps(verify, indent=2)}")

    # Close all instances when done
    await pump_swap.close()

if __name__ == "__main__":
    asyncio.run(main())

Features

  • Create, sign, and send Solana transactions for Pump.fun tokens.
  • Fetch wallet balances and Solana price in USD.
  • Automatically derive bonding curve and associated token addresses.
  • Utility functions for converting USD to lamports and tokens.

Installation

Install via pip:

pip install pump_swap

Metadata

Release files for pump-swap 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pump-swap 0.7.0
File Size Uploaded
pump_swap-0.7.0.tar.gz 8.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pump-swap 0.7.0
File Interpreter ABI Platform
pump_swap-0.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.3 kB

Release files / pump_swap-0.7.0.tar.gz

Download URL pump_swap-0.7.0.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
67d772b860ac3e6c3c8598996f24dd6d78b112e26e2efc0569f572aa0d5ddcff
BLAKE2b-256 checksum
How to use checksums
10d0ff8e92e88fd9d0c74005d2c965761d2af88a0231f1fd41ac501c71952904
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.6

Release files / pump_swap-0.7.0-py3-none-any.whl

Download URL pump_swap-0.7.0-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8fd4e8dbadd59da694018d4df9a7cbceecd681aa3ab359b260e80e84137315bd
BLAKE2b-256 checksum
How to use checksums
8fcd49cd93665f63045de7f863ba89a94081ed974dc1ff7ccf716d14e01f6663
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.6

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 release files

0.6.9

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page