Open elvise7777 opened 2 years ago
@elvise7777 When I looked at the method.py file of the web3 python module, I found the description of this type of error.
Directly calls to methods are not supported. Methods must be called from an module instance, usually attached to a web3 instance.
So did you creat a web3 instance successfully? If you comfirm it, don't forget add these two pieces of code after your web3 instance.
w3.middleware_onion.add(construct_sign_and_send_raw_middleware(sender))
w3.middleware_onion.inject(geth_poa_middleware, layer=0)
Good luck : )
I import ModuleV2 from web3.module and solve the problem. But the bundle not execute. Did you test the flashbots successfully on goerli? Thank you for your response.
@elvise7777 When I looked at the method.py file of the web3 python module, I found the description of this type of error.
Directly calls to methods are not supported. Methods must be called from an module instance, usually attached to a web3 instance.
So did you creat a web3 instance successfully? If you comfirm it, don't forget add these two pieces of code after your web3 instance.w3.middleware_onion.add(construct_sign_and_send_raw_middleware(sender))
w3.middleware_onion.inject(geth_poa_middleware, layer=0)
Good luck : )
@elvise7777 Sorry for taking so long to reply to you. I tested flashbots successfully on goerli include create contracts and swap tokens and even arbitrage. You can adjust the gas price and coinbase trasfer amount to a higher value. If it still fails, you can use flashbots simulate api to check the specific reason. You can read the document of troubleshooting here to learn more. Wish you all the best~
@lecoos hi~ How to set or switch to the url of the testnet in the goerli testnet test? Is the url of the testnet set as flashbots.DEFAULT_FLASHBOTS_RELAY='https://relay-goerli.flashbots.net' Thank you
@hongwei520
You can try to modify in three places.
I modified all these for my test : )
Good luck
@lecoos Thank you. After I execute the script, I finally see the transaction record. I used the eip1559.py in the example at the beginning, but there are many problems. So if I execute the script on the main network, do I need to submit the bundle through a loop?
@hongwei520 It depends on the purpose of your transactions. If you just want your transactions to be on-chain, like deploy, you can submit the bundle through a loop. While if your transactions are time sensitive, like arbitrage, you better determine an accurate target block number instead of using loop. Of course, you can send some same bundles to improve success rate, but flashbots relayer may reject you due to the preventions of DoS, so draw a fine line : )
@lecoos If I set the current block number + 1, and then send multiple bundles, the transaction will have a higher chance of succeeding in the current block number + 1 block. Is it like this?
@hongwei520 Actually this method will improve the success rate only if your network is not smooth. If the flashbots relayer could receive your bundle normaly, the chance only depends on your transactions.
@lecoos Well, that is, I just need to send one. I also encountered a problem when using the example. It does not necessarily wait for the result and will error out TransactionNotFound. I know that the transaction may not be packaged, but I don't know how to judge it. Is this transaction pending or failed because I have waited for a long time and still haven't seen the transaction record and re-executing the script returns notfound and the hash of the transaction is the same as before. This is why
@hongwei520 I just test the example script eip1559.py successfully on goerli. If you confirm your code is correct, you can use flashbots simulate function to check for the specific reason.
@lecoos alright, thank you very much
@lecoos I tested it successfully on the testnet but failed on the mainnet. For the code I just did change the chainId to 1. I tested using web3.eth.sendRawTransaction to send the signed transaction directly and it was successful but using the bundle to send to the relayer It seems that the relay did not receive the package I submitted. My code is very simple 'https://rentry.co/pnyk7' Please where do I need to modify to adapt to the main network? Thank you
@hongwei520
@lecoos The test is successful, there is no problem with the code, it seems to be a problem of cost, it seems that the gas price was as high as 60gwei during the test period yesterday, so it failed
@lecoos If I don't bribe the miner via coinbase.transfer, but add a transfer transaction to the bundle, would that work? If it works, then how do I just specify the miner as the recipient?
@hongwei520 You can write a contract to implement transfer function, and specify coinbase as the recipent in contract. But there is no different from coinbase.transfer. 😂
@lecoos Is it possible to add a tip without a contract, like adding it to a bundle
@hongwei520 No such method now, cuz you can't specify miner except coinbase in contract.
@lecoos Understood thank you
@lecoos I sent bundle to miners in block 14588272 on mainnet, but do not get the receipt. The maxFeePerGas was 49 and the maxPriorityFeePerGas was 3 which was higher than other transactions in block. I never send bundle successfully on mainnet.
@elvise7777 Can you post your simple code, pay attention to privacy protection.
tx2: TxParams = { "from": self.ACCOUNT_FROM.address, "to": self.CONTRACT_AD, "value": 0, "nonce": nonce, "gas": 1700000, "maxFeePerGas": Web3.toWei(gasPrice, "gwei"), "maxPriorityFeePerGas": Web3.toWei(priorityGas, "gwei"), "chainId": 1, "data": encodeBytesData }
bundle = [ { "signer": self.ACCOUNT_FROM, "transaction": tx2 } ]
results = [] for target_block in [block + k + 1 for k in range(3)]: results.append( self.w3.flashbots.send_bundle(bundle, target_block_number=target_block) )
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}") return receipt except TransactionNotFound: print("Bundle was not executed") return "Bundle was not executed"
@lecoos I send bribe by contract. Does the miners not package the transaction which may be reverted by contract even pay the higher gas. Thank u, sir.
@elvise7777 If you don't set the revertingTxHashes field, the miners will not pack your reverted transactions even you pay a high gas. You can use simulate call to check the failed reason like this:
simulation = w3.flashbots.simulate(bundled_transactions=bundle, block_tag=w3.eth.block_number)
@lecoos I simulate the bundle successfully. simulation = self.w3.flashbots.simulate(bundle, block)
@lecoos Does the successful simulation mean my bundle will be executed in the current block?
@elvise7777 Nope. Simulation could only be used to simulate a bundle against a specific history block number, or simulate a bundle at the top of the next block. So you can't predict your bundle execution by the result of simulation, just for finding failed reason.
@lecoos Got it. It's hard to do arbitrage on mainnet. Thanks a lot.
@lecoos Do you know why it take a long time almost 20s before send to miner?
@elvise7777 The flashbots relayer will prerun transactions, package txns into mega bundle and other processes. 20s should be reasonable if it was at the peak trading period. I think you can increase the gas price so that your txns are at the forefront of prerun process, to shorten the on-chain time.
@lecoos Thanks a lot. I only send one arb transaction successful, after a loooooong time. Sending bribe through contract or increasing the gas price, which way is better?
@elvise7777 Gas price. And you should notice base fee if you use EIP1559.
@lecoos Thanks a lot.
Traceback (most recent call last): File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py", line 1483, in _exec pydev_imports.execfile(file, globals, locals) # execute the script File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "/Users/elvise/Downloads/flashloan/flashbotsTest.py", line 56, in
w3.flashbots.send_bundle(bundle, target_block_number=target_block)
File "/Users/elvise/Downloads/flashloan/venv/lib/python3.9/site-packages/web3/method.py", line 142, in get
return obj.retrieve_caller_fn(self)
AttributeError: 'Flashbots' object has no attribute 'retrieve_caller_fn'