I am initiating a transaction using the following function.
contract = web3.eth.contract(address=router_address, abi=PancakeABI)
nonce = web3.eth.get_transaction_count(sender_address)
amountIn = (web3.toWei(0.0001, 'ether'))
start = time.time()
print(web3.toWei('0.002', 'ether'))
toBuyBNBAmount = web3.toWei("0.0002", 'ether')
pancakeswap2_txn = contract.functions.swapExactETHForTokens(
0, # Here setup the minimum destination token you
# want to have, you can do some math, or you
# can put a 0 if you don't want to care
[spend, contract_id],
sender_address,
(int(time.time()) + 1000000)
).buildTransaction({
'from': sender_address,
'value': toBuyBNBAmount, # This is the Token(BNB) amount
# you want to Swap from
'gas': 160000,
'gasPrice': web3.toWei('5', 'gwei'),
'nonce': nonce
})
signed_txn = web3.eth.account.sign_transaction(pancakeswap2_txn, private_key=private)
tx_token = web3.eth.send_raw_transaction(signed_txn.rawTransaction)
print(web3.toHex(tx_token))
However, each time my transaction is being reverted:
https://bscscan.com/tx/0x021ea258b937ba1575cdf5aed0f49fcad1143f2fc8b25eb8efffdc2347ca6729