26 min read
While this TypeScript guide demonstrates Yellowstone gRPC integration, we strongly recommend using Rust or Go for production environments processing high-volume transaction streams.
Node.js's single-threaded runtime can struggle with the high data throughput that Solana/Yellowstone gRPC can deliver, potentially causing slow subscriber issues and memory pressure. Compiled languages like Rust and Go offer significantly better performance for processing large volumes of streaming data.
If you're building systems that need to process all transactions from busy programs or track multiple programs simultaneously, consider implementing your solution in a compiled language instead.
Check out our Rust implementation guide or Go Documentation for a high-performance alternative.
Overview
In this guide, we will learn how to create a Solana trading bot that copies trades of a specified wallet on the Pump.fun DEX using QuickNode's Metis add-on for the Pump.fun API and Yellowstone Geyser gRPC. This guide is designed for developers with a solid understanding of JavaScript, Solana, and basic DeFi concepts.
A visual learner? Follow along with this video to learn how to create a Solana copy trading bot using Pump.fun.
What You Will Do
- Get an overview of Pump.fun and Yellowstone
- Create a JavaScript trading bot that monitors wallets' trades on Pump.fun and copies their buy transactions based on a predefined strategy
- Simulate target wallet transactions and test the bot's functionality
If you prefer using TypeScript or the new Solana Kit library, check out our guide on Monitoring Programs with Yellowstone and how to Build with the Pump.fun API using Solana Kit.
What You Will Need
- Intermediate knowledge of Solana development and DeFi concepts
- Experience with JavaScript and Node.js
- A Solana file system wallet with a SOL balance (run
solana-keygen -h
for support creating a new wallet) - A QuickNode Account with Yellowstone Geyser gRPC add-on enabled
Connect to a Solana Cluster with Your QuickNode Endpoint
To build on Solana, you'll need an API endpoint to connect with the network. You're welcome to use public nodes or deploy and manage your own infrastructure; however, if you'd like 8x faster response times, you can leave the heavy lifting to us.
See why over 50% of projects on Solana choose QuickNode and sign up for a free account here. We're going to use a Solana Mainnet endpoint.
Copy the HTTP Provider link:
What is Metis?
Metis is a powerful tool for developers to access liquidity on Solana. By integrating Jupiter's V6 Swap API, Jupiter's Limit Order API, Pump.fun trading, Trading websockets, and more, you have access to the tools you need to build robust trading tools that access many DeFi protocols across Solana. Metis is available as an add-on on the QuickNode Marketplace, here or a public endpoint is available at JupiterAPI.com.
Using the Pump.fun API
In this guide, we will primarily focus on the /pump-fun/swap
endpoint (docs), which allows us to fetch a serialized transaction for executing a swap on Pump.fun. This endpoint requires the following parameters:
wallet
: The public key of the wallet executing the tradetype
: The type of trade ("BUY" or "SELL")mint
: The mint address of the token being tradedinAmount
: The amount of the input token (in raw units)priorityFeeLevel
(optional): The priority fee level for the trade ("low", "medium", "high", or "auto")slippageBps
(optional): The maximum slippage (in basis points) allowed for the trade
The response from this endpoint contains a base64-encoded Solana transaction that can be signed and sent to the network to execute the trade.
What is Yellowstone?
Yellowstone is a Marketplace Add-on provides a gRPC-based API that enables developers to create custom subscriptions and receive real-time updates as events occur on the Solana network. This makes it an excellent tool for building applications that require real-time monitoring of blockchain activity, such as trading bots, analytics platforms, and decentralized applications (dApps).
To use Yellowstone, we need to create a subscription request that specifies the accounts, transactions, and other events we want to monitor. Yellowstone will then stream real-time updates for the specified events.
For more information on Yellowstone, check out:
Setting Up the Project
This guide is for educational purposes only and should not be considered financial advice. Trading bots can be risky and may result in financial loss. Always do your own research and consider consulting with a financial advisor before using trading bots or engaging in trading activities. Make sure any code you run is secure and thoroughly tested before using it with real funds.
Before we start building the trading bot, let's set up our project and install the necessary dependencies.
-
Create a new directory for your project and navigate to it in your terminal.
-
Initialize a new Node.js project by running the following command:
npm init -y
-
Install the required dependencies by running the following command:
npm install @solana/web3.js@1 bs58 dotenv @triton-one/yellowstone-grpc
@solana/web3.js
: The legacy version of Solana Web3.js library for interacting with the Solana blockchainbs58
: A library for working with Base58 encoding/decodingdotenv
: A library for loading environment variables from a.env
file@triton-one/yellowstone-grpc
: The Yellowstone gRPC client library
-
Create a new file called
bot.js
in your project directory. -
Create a
.env
file in your project directory and add the following environment variables:SOLANA_RPC=<your_solana_rpc_endpoint> # https://example.quiknode.pro/replace-me-123/
SECRET_KEY=<your_wallet_secret_key> # [0, 0, ..., 0]
METIS_ENDPOINT=<your_metis_endpoint> # https://jupiter-swap-api.quiknode.pro/REPLACE_ME
YELLOWSTONE_ENDPOINT=<your_yellowstone_endpoint> # https://example.solana-mainnet.quiknode.pro:10000
YELLOWSTONE_TOKEN=<your_yellowstone_token> # abc...xyzReplace the placeholders with your actual values:
SOLANA_RPC
: Your QuickNode Solana Mainnet RPC endpoint (you can find this in your QuickNode dashboard)SECRET_KEY
: Your Solana wallet's secret key (in JSON array format, e.g.,[0, 0, ..., 0]
). Make sure this wallet is funded with SOL for the bot to execute trades.METIS_ENDPOINT
: Your QuickNode Metis endpoint for the Pump.fun API (e.g.,https://jupiter-swap-api.quiknode.pro/...
). If you do not have the Metis add-on, you can use the public endpoint:https://public.jupiterapi.com
(note: the public endpoint may incur transaction fees--check jupiterapi.com for details).YELLOWSTONE_ENDPOINT
: Your Yellowstone endpoint (Note: this should be a gRPC endpoint, ending in:10000
- more information is available here)YELLOWSTONE_TOKEN
: Your Yellowstone API token (locate your token here)