A small CLI to buy a token on Solana using Jupiter swap API, with the token mint configured in config.py.
- Validates amount of SOL (first arg)
- Builds swap using Jupiter's official API (
/swap/v1/) and signs withid.jsonkeypair
- Ensure
config.pycontains:mint: token mint to buyrpc: your RPC endpoint URL
- Place your Solana keypair in
id.json(array of 64 or 32 integers) - Optional: Set
JUPITER_API_KEYenvironment variable for higher rate limits
Create venv and install deps:
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtThe id.json file contains your Solana keypair and should be treated with extreme care as it controls your wallet.
You can use solana-keygen grind to generate a keypair with a vanity address (custom prefix):
# Generate a keypair with address starting with "Buy"
solana-keygen grind --starts-with Buy:1 --ignore-case
# Generate a keypair with address ending with "SOL"
solana-keygen grind --ends-with SOL:1 --ignore-case
# Generate a keypair with specific prefix (case-sensitive)
solana-keygen grind --starts-with abcd:1This will output the keypair array that you can save to id.json.
solana-keygen can be installed via:
brew install solana
Important: Always secure your id.json file with proper permissions:
# Set read-only permissions for owner only
chmod 600 id.json
# Verify permissions
ls -la id.json
# Should show: -rw------- 1 user group size date id.jsonSecurity Best Practices:
- Never share your
id.jsonfile or commit it to version control - Keep backups in secure, encrypted storage
- Consider using a hardware wallet for large amounts
- Use a separate keypair for testing/development
Dry-run (build but do not send):
python buy.py 0.005Broadcast:
python buy.py 0.005 --no-dry-run --yesOptions:
--slippage-bpsdefault 100 (1%)--priority-feelamports orauto--yesskip confirmation--no-dry-runto broadcast
API Information:
- Uses Jupiter's official API endpoints (
lite-api.jup.ag/swap/v1/) - Supports optional API key for paid plans (set
JUPITER_API_KEYenvironment variable) - Free tier available without API key
For automated recurring purchases (dollar-cost averaging), use the included buy.sh script:
# Make sure it's executable
chmod +x buy.sh
# Run recurring purchases
./buy.shThe script will:
- Execute 30 purchases of 0.01 SOL each
- Use 25 basis points (0.25%) slippage
- Wait 5 minutes (300 seconds) between purchases
- Automatically confirm each transaction
Edit buy.sh to modify the default values:
ITERATIONS=30 # Number of purchases
SIZE=0.01 # SOL amount per purchase
SLIPPAGE=25 # Slippage in basis points (25 = 0.25%)
SLEEP=300 # Seconds between purchasesImportant Notes:
- Ensure sufficient SOL balance for all planned purchases
- Monitor your wallet and the script's progress
- Consider network congestion and transaction fees
- The script runs automatically - use
Ctrl+Cto stop if needed