Solana ChatGPT Kit

Solana ChatGPT Kit

π The World's First ChatGPT App with Native Solana Wallet Integration
Perform Solana blockchain operations directly from ChatGPT using natural language. Swap tokens, send SOL, check balances, stake assets, and moreβall without leaving your conversation.
π What Makes This Special?
This is the first-ever ChatGPT application that combines:
- β OpenAI Apps SDK - Native ChatGPT integration with MCP (Model Context Protocol)
- β Full Solana Wallet Support - Use private keys or browser wallet extensions
- β Interactive Widgets - Beautiful, responsive UI rendered directly in ChatGPT
- β Natural Language Commands - No technical knowledge required
- β Production Ready - Fully functional Solana operations powered by Jupiter
β¨ Features
π± Token Swaps (Jupiter Integration)
- Swap SOL, USDC, USDT, and any SPL token
- Real-time price quotes that update as you type
- Support for token symbols (SOL, USDC) or mint addresses
- Support for ticker symbols like
$SEND - Low slippage and optimal routing via Jupiter
- Transaction links to Solscan explorer
πΈ SOL Transfers
- Send SOL to any wallet address
- SNS Domain Support (.sol domains via Bonfida)
- AllDomains Support (.superteam, .solana, and other TLDs)
- x402 Payment Protocol (External Wallet Mode): Optional $0.001 USDC API fee from user's wallet
- Explicit confirmation before sending
- Transaction tracking and verification
π Balance Checking
- Check SOL balance for any address
- Query balances using SNS/AllDomains names
- Instant balance lookup with address resolution
π° Token Staking
- Stake SOL into liquid staking tokens (LSTs)
- Default support for JupSOL
- Powered by Jupiter's swap infrastructure
- Earn yield while maintaining liquidity
π΅ Token Price Lookup
- Get real-time token prices via Jupiter
- Query by mint address (contract address)
- USD price data with formatting
π Quick Start
Prerequisites
- Node.js 18+ and pnpm
- A Solana wallet with some SOL
- ChatGPT with developer mode access
Installation
# Clone the repository
git clone https://github.com/The-x-35/solana-chatgpt-kit.git
cd solana-chatgpt-kit
# Install dependencies
pnpm installEnvironment Setup
Create a .env.local file:
# Required: Your Solana wallet private key (base58 encoded)
SOLANA_PRIVATE_KEY=your_base58_private_key_here
# Required for external wallet mode: Treasury address for x402 payment fees
# (Only needed if externalWallet = true in lib/solana-config.ts)
X402_TREASURY_ADDRESS=your_treasury_wallet_address_here
# Optional: x402 Facilitator URL (defaults to PayAI facilitator)
FACILITATOR_URL=https://facilitator.payai.network
# 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_keyGetting Your Private Key:
# Create a new wallet
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));
"β οΈ Security Note: Never share your private key or commit it to git. Use a dedicated wallet for this app with only the funds you need.
Development
# Start the development server
pnpm devOpen http://localhost:3000 to see the app.
Deploy to Production
The app is optimized for Vercel deployment with automatic environment detection.
Connect to ChatGPT
- Deploy your app (or use ngrok for local testing:
ngrok http 3000) - In ChatGPT, go to Settings β Connectors β Create
- Add your MCP server URL:
https://your-app.vercel.app/mcp - Start using Solana commands in ChatGPT!
Note: Connecting MCP servers requires ChatGPT developer mode. See the connection guide.
π¬ Usage Examples
Once connected to ChatGPT, you can use natural language commands:
Swap Tokens
"Swap 0.001 SOL to USDC"
"I want to exchange 10 USDC for SOL"
"Convert 0.5 SOL to $SEND"
"Swap SOL to DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263" (mint address)Send SOL
"Send 0.001 SOL to arpit.sol"
"Transfer 0.5 SOL to user.superteam"
"Send 1 SOL to 26k2...QjC" (wallet address)Check Balances
"What's the balance of arpit.sol?"
"Check balance for user.superteam"
"How much SOL does 26k2...QjC have?"Stake SOL
"Stake 1 SOL into JupSOL"
"I want to stake 0.5 SOL"Get Token Prices
"What's the price of EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v?" (USDC mint)
"Get the price for DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263" (BONK mint)ποΈ Architecture
Key Components
1. MCP Server (app/mcp/route.ts)
The core server that registers tools and resources with ChatGPT:
- Tools: Executable functions (swap, transfer, balance check, etc.)
- Resources: HTML widgets rendered in ChatGPT iframes
- Cross-linking: Tools reference resources via
templateUri
2. API Routes (app/api/)
Backend endpoints that handle blockchain operations:
/api/swap/quote- Get Jupiter swap quotes/api/swap/execute- Execute token swaps/api/transfer- Send SOL transactions/api/wallet/balance- Query wallet balances/api/stake- Stake SOL into LSTs/api/price- Token price lookup
3. Wallet Options
Option A: Private Key (Server-Side)
- Store private key in
.env.local - Transactions signed server-side
- Best for automated operations
Option B: Browser Wallet Extension (Coming Soon)
- Connect Phantom, Solflare, or other wallets
- Transactions signed client-side
- Better security for manual operations
4. UI Widgets (app/swap/, app/transfer/, app/stake/)
Beautiful, interactive interfaces rendered in ChatGPT:
- Real-time updates using React hooks
- Dark mode support
- Responsive design for all screen sizes
- Direct integration with ChatGPT theme
5. Address Resolution (lib/address-resolver.ts)
Smart address resolution supporting:
- Raw wallet addresses (base58)
- SNS domains (.sol via Bonfida)
- AllDomains TLDs (.superteam, .solana, etc.)
Technology Stack
- Frontend: Next.js 15, React 19, TypeScript, Tailwind CSS
- Blockchain: Solana Web3.js, SPL Token
- ChatGPT Integration: OpenAI Apps SDK, Model Context Protocol (MCP)
- Swap Infrastructure: Jupiter Aggregator API
- Domain Resolution: Bonfida SNS, AllDomains TLD Parser
- UI Components: Radix UI, Lucide Icons
π§ Configuration
x402 Payment Protocol (External Wallet Mode Only)
When using external wallet mode (externalWallet = true in lib/solana-config.ts), this application implements the x402 payment protocol for API monetization. Each transfer requires a $0.001 USDC payment fee from the user's wallet before execution.
How it works:
- User initiates transfer with browser wallet connected
- Client calls
/api/transferβ Server returns 402 Payment Required - Client automatically creates payment transaction ($0.001 USDC to treasury)
- User signs payment with their wallet (first transaction - USDC payment)
- Client retries request with
X-PAYMENTheader containing proof - Server verifies payment with PayAI facilitator
- Server returns unsigned transfer transaction
- User signs transfer with their wallet (second transaction - SOL transfer)
- Transfer executes successfully
Configuration:
- Set
externalWallet = trueinlib/solana-config.tsto enable - Set
X402_TREASURY_ADDRESSenv variable to your treasury wallet address - Set
FACILITATOR_URLenv variable (optional, defaults to PayAI facilitator) - Fees: $0.001 USDC paid from user's wallet (not server wallet)
- Users must have USDC in their wallet to pay the API fee
- Payment verification handled by PayAI facilitator network
For developers:
- Client-side payment:
x402-solana/clientpackage (seeapp/transfer/page.tsx) - Server-side verification:
x402-solana/serverpackage (seelib/x402-config.ts) - API route integration:
app/api/transfer/route.ts - Payment token: USDC (mainnet:
EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v)
Important Notes:
- When
externalWallet = false(server wallet mode), x402 is disabled and transfers execute directly - Users need USDC tokens in their wallet to pay the $0.001 API fee
- The fee is separate from the SOL being transferred
Credits:
- x402 integration with help from @pranav-singhal
Adding More Tokens
Edit lib/solana-config.ts:
export const TOKENS = {
SOL: 'So11111111111111111111111111111111111111112',
USDC: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
USDT: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',
BONK: 'DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263',
// Add more tokens here
}
export const TOKEN_DECIMALS = {
SOL: 9,
USDC: 6,
USDT: 6,
BONK: 5,
}Custom RPC Endpoint
For better performance, use a dedicated RPC endpoint:
# Recommended providers:
# - Helius (https://helius.dev)
# - QuickNode (https://quicknode.com)
# - Alchemy (https://alchemy.com)
SOLANA_RPC_URL=https://your-custom-rpc-endpoint.comSlippage Tolerance
Adjust slippage in app/api/swap/execute/route.ts:
const slippageBps = 100 // 1% (100 basis points)π API Reference
Swap Quote
GET /api/swap/quote
?inputToken=SOL
&outputToken=USDC
&amount=0.001Response:
{
"inputAmount": 0.001,
"inputToken": "SOL",
"outputAmount": 0.18,
"outputToken": "USDC",
"priceImpact": 0.01,
"quote": {
/* Jupiter quote */
},
"timestamp": "2025-10-24T..."
}Execute Swap
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...",
"timestamp": "2025-10-24T..."
}Check Balance
GET /api/wallet/balance?account=arpit.solResponse:
{
"sol": 1.5,
"lamports": 1500000000,
"resolvedAddress": "26k2...QjC",
"timestamp": "2025-10-24T..."
}π Security Best Practices
Never Expose Private Keys
- Use environment variables only
- Never commit
.env.localto git - Keep
.env.localin.gitignore
Use a Dedicated Wallet
- Create a separate wallet for this app
- Only fund it with what you need
- Don't use your main wallet
Monitor Transactions
- Check Solscan regularly
- Review transaction history
- Set up alerts for large amounts
Rate Limiting (Recommended)
- Add rate limiting to API routes
- Use Jupiter API key for higher limits
- Implement request throttling
Input Validation
- All inputs are validated with Zod schemas
- Address resolution includes error handling
- Transaction amounts are verified
π Troubleshooting
"SOLANA_PRIVATE_KEY not found"
- Ensure
.env.localexists in project root - Check variable name spelling
- Restart dev server after adding env vars
"Invalid private key format"
- Must be base58 encoded
- Use
bs58.encode()to convert secret key array
"Failed to fetch quote"
- Check internet connection
- Verify Jupiter API is accessible
- Try a different RPC endpoint
- Check if tokens are supported by Jupiter
"Insufficient funds"
- Wallet needs SOL for transaction fees (~0.000005 SOL)
- Plus the amount you want to swap/send
- Check balance on Solscan
"Transaction failed"
- Increase slippage tolerance
- Try a smaller amount
- Check if token accounts exist
- Ensure sufficient SOL for fees
Widget not loading in ChatGPT
- Check that app is deployed and accessible
- Verify MCP server URL ends with
/mcp - Check browser console for CORS errors
- Ensure
assetPrefixis set correctly innext.config.ts
π Learn More
Documentation
- OpenAI Apps SDK
- Model Context Protocol
- Solana Documentation
- Jupiter Documentation
- Next.js ChatGPT guide
π€ Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
π Acknowledgments
Special thanks to:
- @pranav-singhal - For help with x402 payment protocol integration
π License
This project is licensed under the MIT License - see the LICENSE file for details.
β οΈ Disclaimer
This software is provided "as is" without warranty of any kind. Use at your own risk. Always verify transactions before confirming. The authors are not responsible for any loss of funds.
Built with β€οΈ for the Solana ecosystem
