0% found this document useful (0 votes)
121 views2 pages

Sniper Bot

This document is a Python script for swapping Solana tokens using the Jupiter API. It includes configuration settings for private keys, token addresses, and transaction parameters, along with functions to find the best swap route, sign transactions, and send them to the Solana network. The script checks for price impact and handles the transaction signing and sending process to execute a token swap.

Uploaded by

said.sabri.pro84
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
121 views2 pages

Sniper Bot

This document is a Python script for swapping Solana tokens using the Jupiter API. It includes configuration settings for private keys, token addresses, and transaction parameters, along with functions to find the best swap route, sign transactions, and send them to the Solana network. The script checks for price impact and handles the transaction signing and sending process to execute a token swap.

Uploaded by

said.sabri.pro84
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import requests

import time
from [Link] import Client
from [Link] import Keypair
from [Link] import Transaction
from [Link] import Pubkey

# === CONFIGURATION ===

PRIVATE_KEY = [ ... ] # Ta clé privée en format array ou hex, ex: [52,144,....] à


générer/extraire via solana-keygen
MEMECOIN_MINT = "TOKEN_ADDRESS_ICI" # ex: HULK... ou 9V7... etc.
AMOUNT_IN_SOL = 0.05 # montant à snip (en SOL)
SLIPPAGE = 2 # % ex: 2 pour 2%
RPC_URL = "[Link]

# Jupiter API endpoints


ROUTE_URL = "[Link]
SWAP_URL = "[Link]

# === LOGIQUE SNIPE ===

def get_best_route(input_mint, output_mint, amount, slippage):


params = {
"inputMint": input_mint,
"outputMint": output_mint,
"amount": int(amount * 1e9), # SOL to lamports
"slippageBps": int(slippage * 100), # e.g. 200 for 2%
"swapMode": "ExactIn"
}
r = [Link](ROUTE_URL, params=params)
routes = [Link]().get('data', [])
return routes[0] if routes else None

def sign_and_send(txn, client, kp):


resp = client.send_raw_transaction(txn)
print("Tx hash:", resp)
return resp

def main():
# Mints
SOL_MINT = "So11111111111111111111111111111111111111112"
memecoin_mint = MEMECOIN_MINT
keypair = Keypair.from_secret_key(bytes(PRIVATE_KEY))
client = Client(RPC_URL)

# === Get best route


print("Recherche du meilleur swap route Jupiter...")
route = get_best_route(SOL_MINT, memecoin_mint, AMOUNT_IN_SOL, SLIPPAGE)
if not route:
print("Aucune route trouvée, token non swappable !")
return

print(f"Prix estimé: {route['outAmount']}, impact prix:


{route['priceImpactPct']*100:.2f}%")
if route['priceImpactPct']*100 > 7: # Par exemple, refuse si price impact > 7%
print("Price impact trop élevé, snipe annulé.")
return
# === Obtenir la transaction de swap prête à signer
swap_params = {
"route": route,
"userPublicKey": str(keypair.public_key),
"wrapUnwrapSol": True
}
swap = [Link](SWAP_URL, json=swap_params).json()
swap_tx = swap['swapTransaction']

# === Signer et envoyer


import base64
from [Link] import Transaction
from [Link] import Message

txn_bytes = base64.b64decode(swap_tx)
txn = [Link](txn_bytes)
[Link]([keypair])

print("Envoi de la transaction...")
resp = client.send_raw_transaction([Link]())
print("Transaction envoyée :", resp)

if __name__ == "__main__":
main()

You might also like