Introduction
In this tutorial, you’ll learn how to retrieve swap (trade) data and price information for Pump.fun tokens using the Moralis Solana API. This includes getting recent swaps, price history, and OHLC data for any token launched on Pump.fun. We’ll use the following Moralis API endpoint:- Get Token Swaps - Fetch swap history and trading data for Solana tokens
Prerequisites
- Node.js v18+ installed
- A Moralis API key (get one free)
Step 1: Set Up Your Project
Create a new directory for your project and initialize it:Step 2: Create the Script
Create a file calledindex.js and add the following code:
YOUR_API_KEY and YOUR_PUMP_FUN_TOKEN_ADDRESS with your actual values.
Step 3: Run the Script
Example Response
Understanding the Response
| Field | Description |
|---|---|
transactionHash | Solana transaction signature |
blockTime | When the swap occurred |
tokenIn | Token being sold (with amount and USD value) |
tokenOut | Token being bought (with amount and USD value) |
walletAddress | Wallet that made the swap |
exchange | DEX where swap occurred |
swapType | Type of trade (buy or sell) |
Next Steps
- Get Pump.fun New/Bonding/Graduated Tokens - Discover tokens
- API Reference - Token Swaps - Full API documentation
- API Reference - Token Price - Price endpoint docs

