Prerequisites
Before you begin, ensure you have:
- Node.js installed
- A Solana wallet with some mainnet SOL
- Your Cleopetra API Key (contact our team to get one)
Installation
Install the required dependencies:Setup
First, set up your environment and API configuration:Transaction Sending Helper
Add this helper function to handle transaction signing and sending:This snippet adds position keypair to all txns in the array, which is unnecessary. Please refer to the advanced example script for optimizations.
Use transaction sending services like Jito in production.
Step 1: Discover Pools
Find the best liquidity pools for a specific token:Step 2: Create DLMM Position
Create a liquidity position in the selected pool:Step 3: Fetch User Positions
Retrieve all positions for your wallet:Step 4: Claim LP Fees
Claim accumulated fees from your first position:Complete Workflow
Put it all together in a complete example:Full example script you can refer.