> ## Documentation Index
> Fetch the complete documentation index at: https://chainstack-docs-polygon-erigon-trace-deprecation.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Solana: Creating a trading and sniping pump.fun bot

> Build a fully coded Python bot that interacts directly with pump.fun Solana programs and accounts for token trading without relying on third-party APIs.

<Frame>
  <iframe width="100%" height="420" src="https://www.youtube.com/embed/7valHrMLvZw" title="How to research & build a bot (pump.fun Solana example)" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen />
</Frame>

**TLDR**

* This Python-based Solana bot monitors the pump.fun on-chain program to detect new tokens, automatically buys them, and optionally sells them soon after. The same bot also supports [letsbonk.fun](https://letsbonk.fun) via a config switch.
* It decodes transaction data using the pump.fun Anchor IDL, fetching token details like mint addresses and bonding curves.
* You configure one or more bot instances as `.yaml` files in the `bots/` directory (strategy, slippage, priority fees, exit rules) and run them with `pump_bot`.
* Learning examples provide reference scripts on Anchor discriminators, price fetching, and subscribing to Solana websockets via `logsSubscribe`, `blockSubscribe`, and Geyser.

The pump.fun project is generating millions of USD in fees and in the volume as evidenced by [pump.fun DefiLlama project page](https://defillama.com/protocol/pump#information).

On top of that, there are project clones popping up.

There are no API endpoints provided by pump.fun itself. At the same time, there are a few third-party projects out there that have figured out how to interact with the pump.fun on-chain programs & accounts and what these are, and they now provide the APIs.

In this project, you'll get to be able to *directly* interact with the pump.fun program & accounts.

See the full project code, including learning examples, in the respective [GitHub repository](https://github.com/chainstacklabs/pump-fun-bot).

## Overview

The project uses the pump.fun IDL to interact with the program and the accounts.

It's very useful to know that the pump.fun program and all the associated accounts is built with the [Anchor framework](https://www.anchor-lang.com/), as a lot of the decoding comes back to Anchor, like the [8 byte instruction signatures/discriminators](https://book.anchor-lang.com/anchor_bts/discriminator.html).

The other thing important to know is that the tokens created with pump.fun are 6 decimal tokens, which is different from the default Solana 9 decimal SPL tokens.

The bot subscribes over WebSocket to a Solana mainnet RPC node and extracts all the newly minted coins created by the pump.fun main program ID [6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P](https://solscan.io/account/6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P). It can listen with `logsSubscribe` (supported by every provider), `blockSubscribe`, or a Geyser stream for the lowest latency.

Once a new coin is minted, the bot buys it and then exits according to your configured strategy. When a token's bonding curve completes, its liquidity graduates to PumpSwap—pump.fun's own AMM. You set the behavior per bot instance in a `.yaml` config file; see [Configure and run the bot](#configure-and-run-the-bot).

## Implementation

The bot is installed and run with [uv](https://github.com/astral-sh/uv). Your secrets—RPC HTTP and WebSocket endpoints, the wallet private key, and optional Geyser credentials—go in a `.env` file, and each bot instance is a `.yaml` file in the `bots/` directory. The core logic has two paths: a listener that detects new tokens, and the buy/sell execution.

### Listener

To construct a buy (and later a sell) transaction, the bot needs the global program and account addresses plus the new token's variables:

* `mint` — the created token address
* `bondingCurve` — the bonding curve account for the new token; this account defines the token price
* `associatedBondingCurve` — the associated token account that holds the tokens bought and sold against the bonding curve

The bot can obtain these addresses three ways, fastest last:

* **`logsSubscribe`** — subscribes to the pump.fun program logs and derives the `associatedBondingCurve` on the fly (it is a PDA of the `bondingCurve`, the token program, and the `mint`). This works on every provider and is the default path.
* **`blockSubscribe`** — subscribes to full blocks filtered to the pump.fun program's `create` instruction and extracts the addresses. Reliable on Chainstack, but not every provider supports it.
* **Geyser** — a gRPC stream for the lowest latency. See the [Geyser implementation guide](/docs/solana-listening-to-pumpfun-token-mint-using-geyser) and [Yellowstone Geyser](/docs/yellowstone-grpc-geyser-plugin).

<Note>
  Earlier versions of the bot relied on `blockSubscribe`, which has stability issues with busy programs and isn't available on every plan. The bot now defaults to `logsSubscribe` (deriving the associated bonding curve locally) and supports Geyser for production. See [Solana: Listening to pump.fun token mint using only logsSubscribe](/docs/solana-listening-to-pumpfun-token-mint-using-only-logssubscribe).
</Note>

### Buy and sell

Using the `mint` and your wallet address (from the private key in `.env`), the bot creates an associated token account to hold the token, fetches the price from the `bondingCurve` account, and submits the buy. The sell path is the reverse and simpler—it fetches the price and submits a sell.

A couple of notes:

* The [Anchor instruction discriminators](https://book.anchor-lang.com/anchor_bts/discriminator.html) are precalculated. See `learning-examples/calculate_discriminator.py`.
* `extreme_fast_mode` (in the bot config) skips the bonding-curve stabilization wait and the RPC price check and buys a fixed token amount directly—faster, but less precise. With it off, the bot waits and price-checks first so the new token's data has propagated across the cluster.

<Warning>
  pump.fun ships breaking on-chain program upgrades—for example, the [2026-04-28 fee-recipient change](https://github.com/pump-fun/pump-public-docs/blob/main/docs/BREAKING_FEE_RECIPIENT.md) altered the buy/sell account lists. When the program changes, account lists and IDLs must be updated, so always cross-check against a recent successful transaction and pull the latest from the repository before running.
</Warning>

## Configure and run the bot

### Install

```shell theme={null}
git clone https://github.com/chainstacklabs/pump-fun-bot.git
cd pump-fun-bot
uv sync
source .venv/bin/activate
uv pip install -e .
```

### Configure

Copy `.env.example` to `.env` and add your Solana RPC endpoints and wallet private key. Then edit or copy a `.yaml` template in `bots/`—each file is a separate bot instance. Key settings:

* `platform` — `"pump_fun"` (default) or `"lets_bonk"` to trade on [letsbonk.fun](https://letsbonk.fun) instead
* `trade.buy_amount`, `trade.buy_slippage`, `trade.sell_slippage` — position size and slippage tolerance
* `trade.exit_strategy` — `"time_based"`, `"tp_sl"` (take-profit/stop-loss), or `"manual"`
* `trade.extreme_fast_mode` — skip the price check and buy a fixed token amount for speed
* `priority_fees` — `enable_fixed` with a `fixed_amount`, or `enable_dynamic` (estimates via `getRecentPrioritizationFees`); see [Solana: priority fees for faster transactions](/docs/solana-how-to-priority-fees-faster-transactions)
* `filters` — restrict trading to tokens matching a name/symbol or created by a specific address
* `geyser` — endpoint and auth token for the Geyser listener

### Run

```shell theme={null}
# Run as the installed package
pump_bot

# Or run directly
uv run src/bot_runner.py
```

Each enabled bot in `bots/` runs as its own instance, so you can run several strategies at once.

<Note>
  This bot is for learning, not production. Also by Chainstack: [pumpfun-cli](https://github.com/chainstacklabs/pumpfun-cli) (a terminal client for trading, launching, and managing tokens, with smart routing between the bonding curve and PumpSwap) and [pumpclaw](https://github.com/chainstacklabs/pumpclaw) (an agent skill that lets AI assistants like Claude Code and Codex operate pumpfun-cli).
</Note>

## Learning examples

The `learning-examples` directory has many scripts for understanding how the bot works and how to interact with Solana. Highlights:

* `listen-new-tokens/listen_logsubscribe_abc.py` — snipes new tokens using only `logsSubscribe`, deriving the associated bonding curve on the fly (no extra `getTransaction` call)
* `listen-new-tokens/compare_listeners.py` — runs the listener methods side by side to see which detects new tokens first
* `bonding-curve-progress/get_bonding_curve_status.py` — checks whether a token's bonding curve is still active or has completed
* `listen-migrations/listen_logsubscribe.py` — detects graduations to PumpSwap; see [Listening to pump.fun migrations to PumpSwap](/docs/solana-listening-to-pumpfun-migrations-to-raydium)
* `compute_associated_bonding_curve.py` — derives the associated bonding curve PDA for a token
* `calculate_discriminator.py` — calculates Anchor instruction discriminators from the IDL in `idl/`
* `pumpswap/` — manual buy and sell examples against the PumpSwap AMM
* `manual_buy.py` / `manual_sell.py` — manual buy and sell with parameters you provide

The IDLs in `idl/` are vendored from [pump-fun/pump-public-docs](https://github.com/pump-fun/pump-public-docs); refresh them from there when the program changes.

<CardGroup>
  <Card title="Ake">
    <img src="https://mintcdn.com/chainstack-docs-polygon-erigon-trace-deprecation/Q3hwLi6Nb4zCIwLs/images/docs/profile_images/1719912994363326464/8_Bi4fdM_400x400.jpg?fit=max&auto=format&n=Q3hwLi6Nb4zCIwLs&q=85&s=fea812ff105af118ec9707089d3c18e9" alt="Ake" style={{width: '80px', height: '80px', borderRadius: '50%', objectFit: 'cover', display: 'block', margin: '0 auto'}} noZoom width="400" height="400" data-path="images/docs/profile_images/1719912994363326464/8_Bi4fdM_400x400.jpg" />

    <Icon icon="code" iconType="solid" /> Director of Developer Experience @ Chainstack
    <br /><Icon icon="screwdriver-wrench" iconType="solid" /> Talk to me all things Web3
    <br />20 years in technology | 8+ years in Web3 full time years experience

    <div style={{display: "flex", justifyContent: "center", gap: "12px"}}>
      <a href="https://github.com/akegaviar/" style={{textDecoration: "none", borderBottom: "none"}}>
        <Icon icon="github" iconType="brands" />
      </a>

      <a href="https://twitter.com/akegaviar" style={{textDecoration: "none", borderBottom: "none"}}>
        <Icon icon="twitter" iconType="brands" />
      </a>

      <a href="https://www.linkedin.com/in/ake/" style={{textDecoration: "none", borderBottom: "none"}}>
        <Icon icon="linkedin" iconType="brands" />
      </a>
    </div>
  </Card>
</CardGroup>
