def main():

sender: LocalAccount = Account.from_key("")

signature: LocalAccount = Account.from_key("")

w3 = Web3(HTTPProvider("https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161"))
flashbot(w3, signature)
contract = ""
abi='[{"constant":false,"inputs":[{"internalType":"address","name":"a","type":"address"},{"internalType":"address","name":"b","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"safeTransfer","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]'
cont = w3.eth.contract(address=contract,abi=abi)
nonce = w3.eth.get_transaction_count(sender.address)
print("current nonce is :" + str(nonce))
tx = cont.functions.safeTransfer("","",0).buildTransaction({
    "from": sender.address,
    "gas": 100000,
    "maxFeePerGas": Web3.toWei(40, "gwei"),
    "maxPriorityFeePerGas": Web3.toWei(3, "gwei"),
    "nonce": nonce,
    "chainId": 1,   
})
tx_signed = sender.sign_transaction(tx)

bundle = [
    {"signed_transaction": tx_signed.rawTransaction},
]

block = w3.eth.block_number
results = []
results.append(
        w3.flashbots.send_bundle(bundle, target_block_number=block + 1))
print(f"Bundle sent to miners in block {block}")

results[-1].wait()
try:
    receipt = results[-1].receipts()
    print(f"Bundle was executed in block {receipt[0].blockNumber}")
except TransactionNotFound:
    print("Bundle was not executed")
    return
print("over ....")
Edit
Pub: 30 Mar 2022 01:16 UTC
Views: 19