This guide explains how to set up and use the Jupiter swap integration in your ChatGPT app.
Already installed! The project includes:
@solana/web3.js- Solana blockchain interactions@solana/spl-token- Token operationsbs58- Base58 encoding for private keys
Create a .env.local file in the project root:
# Required: Your Solana wallet private key (base58 encoded)
SOLANA_PRIVATE_KEY=your_base58_private_key_here
# Optional: Custom RPC endpoint (defaults to public Solana mainnet)
SOLANA_RPC_URL=https://api.mainnet-beta.solana.com
# Optional: Jupiter API key for higher rate limits
JUPITER_API_KEY=your_jupiter_api_keyTo get your base58-encoded private key from Phantom wallet:
// In browser console on Phantom wallet
import bs58 from 'bs58';
// Or use online tool at: https://www.npmjs.com/package/bs58
// If you have secret key array:
const secretKey = new Uint8Array([...]); // Your secret key
const base58Key = bs58.encode(secretKey);
console.log(base58Key);Or create a new wallet programmatically:
npx ts-node -e "
import { Keypair } from '@solana/web3.js';
import bs58 from 'bs58';
const wallet = Keypair.generate();
console.log('Public Key:', wallet.publicKey.toString());
console.log('Private Key (base58):', bs58.encode(wallet.secretKey));
"Your wallet needs SOL for:
- Transaction fees (~0.000005 SOL per swap)
- The tokens you want to swap
Send SOL to your wallet's public key.
pnpm devThe app will be available at http://localhost:3000.
- Deploy your app or use ngrok for local testing
- In ChatGPT: Settings → Connectors → Create
- Add your MCP server URL:
https://your-app.vercel.app/mcp
Try these prompts in ChatGPT:
I want to swap 0.001 SOL to USDC
Swap 0.5 SOL to USDT
Convert 10 USDC to SOL
Open the Jupiter swap interface
- ChatGPT calls the
jupiter_swaptool - A beautiful swap widget appears
- You can:
- Edit the input amount
- See real-time output quotes (updates every 500ms)
- Flip tokens with the swap arrow
- Execute the swap with one click
- Transaction happens automatically using your private key
- Success message shows the Solscan transaction link
- Real-time Quotes: Output amount updates as you type
- Token Flip: Click the arrow to swap input/output tokens
- Dark Mode: Automatically matches ChatGPT's theme
- Error Handling: Clear error messages for issues
- Transaction Links: Direct links to Solscan explorer
- Responsive: Works on mobile, tablet, and desktop
Currently configured tokens:
- SOL - Native Solana token
- USDC - USD Coin (EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v)
- USDT - Tether (Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB)
To add more tokens, edit lib/solana-config.ts:
export const TOKENS = {
SOL: 'So11111111111111111111111111111111111111112',
USDC: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
USDT: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',
BONK: 'DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263', // Example
}
export const TOKEN_DECIMALS = {
SOL: 9,
USDC: 6,
USDT: 6,
BONK: 5,
}GET /api/swap/quote?inputToken=SOL&outputToken=USDC&amount=0.001Response:
{
"inputAmount": 0.001,
"inputToken": "SOL",
"outputAmount": 0.123456,
"outputToken": "USDC",
"priceImpact": 0.01,
"quote": {
/* full Jupiter quote */
},
"timestamp": "2025-10-19T..."
}POST /api/swap/execute
Content-Type: application/json
{
"inputToken": "SOL",
"outputToken": "USDC",
"amount": "0.001"
}Response:
{
"success": true,
"signature": "5xY...",
"explorerUrl": "https://solscan.io/tx/5xY...",
"inputAmount": 0.001,
"inputToken": "SOL",
"outputAmount": 0.123456,
"outputToken": "USDC",
"timestamp": "2025-10-19T..."
}User → ChatGPT → MCP Tool → Widget UI
↓
Quote API (real-time)
↓
User clicks "Swap"
↓
Execute API
↓
Jupiter Quote → Jupiter Swap
↓
Sign with Private Key
↓
Send to Solana Network
↓
Confirm Transaction
↓
Show Success + Explorer Link
-
Never expose private keys
- Use environment variables only
- Never commit
.env.localto git - Add
.env.localto.gitignore
-
Use dedicated wallet
- Don't use your main wallet
- Create a separate wallet for this app
- Only fund it with what you need
-
Monitor transactions
- Check Solscan regularly
- Set up monitoring alerts
- Review transaction history
-
Rate limiting (optional)
- Add rate limiting to API routes
- Use Jupiter API key for higher limits
- Make sure
.env.localexists - Check the variable name is correct
- Restart the dev server after adding env vars
- Must be base58 encoded
- Use
bs58.encode()to convert your secret key
- Check internet connection
- Verify Jupiter API is accessible
- Try a different RPC endpoint
- Make sure wallet has enough SOL
- Need SOL for both swap amount and transaction fees
- Check balance on Solscan
- Increase slippage tolerance (edit in code)
- Try a smaller amount
- Check if token accounts exist
Want to enhance the swap feature? Try:
- Add more tokens: Edit
lib/solana-config.ts - Adjust slippage: Change
slippageBpsin quote/execute routes - Add price charts: Integrate charting library
- Transaction history: Store past swaps in database
- Multi-hop swaps: Support complex routing
- Limit orders: Add Jupiter limit order integration
- Portfolio view: Show token balances
Happy swapping! 🚀