0% found this document useful (0 votes)
27 views

Python 1

Uploaded by

nvictory9000
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Python 1

Uploaded by

nvictory9000
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

from web3 import Web3

import time

# Connect to an Ethereum Node


INFURA_URL = "https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID"
web3 = Web3(Web3.HTTPProvider(INFURA_URL))

if not web3.isConnected():
raise Exception("Failed to connect to Ethereum network")

# User Wallet Details


PRIVATE_KEY = "YOUR_PRIVATE_KEY"
WALLET_ADDRESS = web3.toChecksumAddress("YOUR_WALLET_ADDRESS")

# Uniswap/SushiSwap Router Contract Details


ROUTER_ADDRESS = web3.toChecksumAddress("0xUniswapRouterAddress")
TOKEN_TO_SNIPE = web3.toChecksumAddress("0xTargetTokenAddress")

# Uniswap Router ABI (Simplified for 'swapExactETHForTokens')


ROUTER_ABI = [
{
"constant": False,
"inputs": [
{"name": "amountOutMin", "type": "uint256"},
{"name": "path", "type": "address[]"},
{"name": "to", "type": "address"},
{"name": "deadline", "type": "uint256"}
],
"name": "swapExactETHForTokens",
"outputs": [{"name": "amounts", "type": "uint256[]"}],
"payable": True,
"stateMutability": "payable",
"type": "function"
}
]

router = web3.eth.contract(address=ROUTER_ADDRESS, abi=ROUTER_ABI)

# Snipe Function
def snipe_token():
amount_in_wei = web3.toWei(0.1, 'ether') # ETH to spend
amount_out_min = 0 # Minimum tokens to accept (use slippage control)
path = [web3.toChecksumAddress("0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"),
TOKEN_TO_SNIPE]
deadline = int(time.time()) + 60 # 1-minute deadline

# Build Transaction
transaction = router.functions.swapExactETHForTokens(
amount_out_min, # Minimum amount of tokens
path, # Trade path: ETH -> Target Token
WALLET_ADDRESS, # Tokens sent to your wallet
deadline # Deadline for transaction execution
).buildTransaction({
'from': WALLET_ADDRESS,
'value': amount_in_wei, # Amount of ETH to spend
'gas': 250000, # Estimated Gas Limit
'gasPrice': web3.toWei(50, 'gwei'), # Gas Price
'nonce': web3.eth.getTransactionCount(WALLET_ADDRESS)
})
# Sign and Send Transaction
signed_txn = web3.eth.account.signTransaction(transaction, PRIVATE_KEY)
tx_hash = web3.eth.sendRawTransaction(signed_txn.rawTransaction)

print(f"Transaction sent with hash: {tx_hash.hex()}")

# Example Usage
if __name__ == "__main__":
try:
print("Starting the sniping bot...")
snipe_token()
except Exception as error:
print(f"Error occurred: {error}")

You might also like