Detect Buy/Sell Transaction Type on Pumpfun
Learn how to detect Pumpfun transaction type using Solana Yellowstone geyser gRPC and IDL-based parsers.
Tracking buy and sell events on Pump.Fun is crucial for trading bots and market analysis. This guide details how to utilize Solana's Yellowstone gRPC stream to efficiently capture and parse real-time transaction data, enabling instant detection of token swaps and providing a significant edge in the fast-paced Solana memecoin market.
The complete source code for this project is available on GitHub.
Please feel free to clone the repository and try it out. Additionally, you will find other relevant and useful code examples related to gRPC and streaming here.
Step-by-Step Breakdown
This project consists of two key components:
Streaming Pump.fun Transactions via Yellowstone gRPC
Parsing the Received transactions along with events
Identifying Buy / Sell transactions based on the Pump Events
Streaming Transactions Using gRPC
The first step involves initializing the Solana Yellowstone Client. You can get Solana Yellowstone gRPC access from the Shyft Dashboard. Please check out our gRPC Authentication Docs for more details.
Initializing the Client
Once you have the authentication details, you can initialize the client in the following manner,
import Client from "@triton-one/yellowstone-grpc";
const client = new Client(
"YOUR-GRPC-ENDPOINT", //yellowstone grpc url
"GRPC-ACCESS-TOKEN", //authentication token
undefined
);use yellowstone_grpc_client::{GeyserGrpcClient, Interceptor}
async fn connect(&self) -> anyhow::Result<GeyserGrpcClient<impl Interceptor>> {
GeyserGrpcClient::build_from_shared(self.endpoint.clone())? //grpc url
.x_token(Some(self.x_token.clone()))? //grpc auth token
.connect_timeout(Duration::from_secs(10))
.timeout(Duration::from_secs(10))
.tls_config(ClientTlsConfig::new().with_native_roots())?
.max_decoding_message_size(1024 * 1024 * 1024)
.connect()
.await
.map_err(Into::into)
}You can use any Yellowstone gRPC endpoint with this client. An access token is optional, as some gRPC services don't require authentication.
The Rust client supports several additional options, as demonstrated in the example above. Most of these options are also available for the TS client, where they are passed as the third argument to the Client constructor.
Specifying what data to stream from gRPC
To specify what on-chain data, we send a SubscribeRequest over the existing Solana Yellowstone gRPC client. These Request allows you to filter for specific accounts, transactions, slots, or other Solana on-chain events, giving you full control over the data you receive. You can find out more about Subscribe Requests here.
Subscribe Requests specify what data to stream by the means of filters. When you want to stream transactions, you use a transaction filter. Inside this filter, you tell it which program's transactions you're interested in by providing its "program ID" in the "account" field. The example below demonstrates how to initiate a gRPC stream by sending a SubscribeRequest using a standard gRPC client:
Once established, the stream will begin sending data directly to your application. You have the flexibility to modify your subscription on the fly, allowing you to change the data specifications you receive without stopping your stream. For more details on reconnecting and re-starting the stream from a specific slot, or closing your gRPC connection, you can find additional information in our documentation.
Parsing the received transaction
Once a raw Solana transaction is received via the Yellowstone gRPC stream, it must be parsed to extract meaningful, human-readable data. For JavaScript/TypeScript applications, we use Shyft's IDL-based transaction parser, which decodes the transactions received from the gRPC into structured data based on the respective program's IDL. On Rust however, we use a interface generated by solores to parse the transaction instruction.
Detecting Buy/Sell Events
Once a valid Pump.fun transaction is identified and decoded, transactionOutput(parsedTxn) extracts key details about the buy or sell event, such as:
TYPE: Whether it was a "buy" or "sell" action.MINT: The token's address involved in the swap.SIGNER: The wallet address that initiated the transaction (the buyer or seller).TOKEN AMOUNT: How much of the specific token was bought or sold.SOL AMOUNT: The amount of SOL exchanged in the transaction.SIGNATURE: The unique transaction signature, which can be used to view the transaction on a Solana block explorer.
Finally, these critical details are printed to the console in a clear, readable format, providing instant alerts for every buy and sell event occurring on Pump.fun. This allows traders and bots to react swiftly to market movements and liquidity changes.
Important Links
Solana gRPC Documentation β In-depth technical docs for implementing real-time streaming with Yellowstone gRPC and Geyser plugin on Solana.
Blogs on Solana gRPC Streaming β Guides, use cases, and performance benchmarks for building low-latency Solana applications using gRPC-based infrastructure.
Solana DeFi Code Snippets & Examples β Ready-to-use code snippets and integrations for common DeFi protocols, transaction parsers, and real-time Solana data streaming use cases.
Last updated
Was this helpful?