How can i turn this buy function into a transaction that buys and sell in a single transaction?
The reason behind this is to check if a token is a honeypot and will not allow me sell the token, but i dont know how to go on from here. Maybe there is better way to check if a address is a honeypot(www.honeypot.is is not working good), but Nonetheless can it be done with web3?
contract = web3.eth.contract(address=uniswap_factory, abi=uniswap_factory_abi)
contractbuy = web3.eth.contract(address=panRouterContractAddress, abi=panabi)
def buy(token, wbnb_amount):
spend = web3.toChecksumAddress("0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c") # wbnb contract address
tokenToBuy = web3.toChecksumAddress(token)
nonce = web3.eth.get_transaction_count(sender_address)
pancakeswap2_txn = contractbuy.functions.swapExactETHForTokens(
0, # set to 0, or specify minimum amount of token you want to receive - consider decimals!!!
[spend, tokenToBuy],
sender_address,
(int(time.time()) + 10000)
).buildTransaction({
'from': sender_address,
'value': web3.toWei(wbnb_amount, 'ether'), # This is the Token(BNB) amount you want to Swap from
'gasPrice': web3.toWei('5', 'gwei'),
'nonce': nonce,
})
signed_txn = web3.eth.account.sign_transaction(pancakeswap2_txn,
private_key=privatekey)
tx_token = web3.eth.send_raw_transaction(signed_txn.rawTransaction)
transaction_tx = web3.toHex(tx_token)
return transaction_tx