A Go client for the Jupiter Aggregator API - the leading DEX aggregator on Solana.
- 💱 Swap Quotes - Get best-price quotes across all Solana DEXs
- 📝 Swap Transactions - Build ready-to-sign swap transactions
- 💰 Price API - Fetch token prices in SOL or USDC
- 🎯 Slippage Control - Configure slippage tolerance
- ⚡ Priority Fees - Set priority fees for faster execution
- 🛣️ Route Information - Full routing details for transparency
go get github.com/Laminar-Bot/jupiter-gopackage main
import (
"context"
"fmt"
"log"
"github.com/Laminar-Bot/jupiter-go"
"github.com/shopspring/decimal"
)
func main() {
client := jupiter.NewClient(jupiter.DefaultConfig())
// Get a quote: Buy tokens with 0.5 SOL
quote, err := client.GetQuote(context.Background(), &jupiter.QuoteRequest{
InputMint: jupiter.NativeSOL,
OutputMint: "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263", // BONK
Amount: jupiter.SOLToLamports(decimal.NewFromFloat(0.5)),
SlippageBps: 100, // 1%
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("You'll receive: %s tokens\n", quote.OutAmount)
fmt.Printf("Price impact: %s%%\n", quote.PriceImpactPct)
}// Get quote first (see above)
// Build swap transaction
swap, err := client.GetSwapTransaction(ctx, &jupiter.SwapRequest{
QuoteResponse: quote,
UserPublicKey: "YourWalletAddress...",
PrioritizationFeeLamports: 50000, // Optional priority fee
})
if err != nil {
log.Fatal(err)
}
// swap.SwapTransaction contains base64-encoded transaction
// Decode, sign with your wallet, and send to RPC// Get single token price
price, err := client.GetPrice(ctx, "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263")
fmt.Printf("BONK price: $%s\n", price.Price)
// Get multiple prices
prices, err := client.GetPrices(ctx, []string{
"DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263", // BONK
"7GCihgDB8fe6KNjn2MYtkzZcRjQy3t9GHdC8uHYmW2hr", // POPCAT
})// Build a buy quote (SOL -> Token)
quote, _ := jupiter.BuildBuyQuote(tokenMint, amountSOL, slippageBps)
// Build a sell quote (Token -> SOL)
quote, _ := jupiter.BuildSellQuote(tokenMint, amountTokens, decimals, slippageBps)
// Convert SOL to lamports
lamports := jupiter.SOLToLamports(decimal.NewFromFloat(1.5))
// Extract price from quote
price := jupiter.PriceFromQuote(quote) // Returns SOL per tokenclient := jupiter.NewClient(jupiter.Config{
BaseURL: "https://quote-api.jup.ag/v6", // default
PriceURL: "https://price.jup.ag/v6", // default
TimeoutSec: 30,
DefaultSlippage: 100, // 1% in basis points
DefaultPriorityFee: 50000, // lamports
})jupiter.NativeSOL // So11111111111111111111111111111111111111112
jupiter.USDC // EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
jupiter.USDT // Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB
jupiter.SlippageTight // 50 bps (0.5%)
jupiter.SlippageNormal // 100 bps (1%)
jupiter.SlippageRelaxed // 300 bps (3%)quote, err := client.GetQuote(ctx, req)
if err != nil {
var apiErr *jupiter.APIError
if errors.As(err, &apiErr) {
switch apiErr.Code {
case "ROUTE_NOT_FOUND":
// No route available for this pair
case "AMOUNT_TOO_SMALL":
// Increase swap amount
}
}
return err
}Contributions are welcome! Please read our Contributing Guide first.
MIT License - see LICENSE for details.