flashbots.py 报字典合并错误

错误提示: TypeError: unsupported operand type(s) for |: 'dict' and 'dict'

代码:

from flashbots import flashbot
from flashbots.types import SignTx
from eth_account.account import Account
from web3 import Web3, HTTPProvider, exceptions
from web3.middleware import construct_sign_and_send_raw_middleware
from web3.types import TxParams, Wei
from eth_account.signers.local import LocalAccount
import os
import requests
import math
#os.environ["http_proxy"] = "http://127.0.0.1:7890"
#os.environ["https_proxy"] = "http://127.0.0.1:7890"
"""
In this example we setup a transaction for 0.1 eth with an appropriate gasprice.
From here we will use Flashbots to pass a bundle with the needed content.
"""

# signifies your identify to the flashbots network
FLASHBOTS_SIGNATURE: LocalAccount = Account.create()
ETH_ACCOUNT: LocalAccount = Account.from_key(pravity)
SEND_TO: str = address  # Eth address to send to

print("connecting to RPC")
w3 = Web3(HTTPProvider("gorel rpc"))
w3.middleware_onion.add(construct_sign_and_send_raw_middleware(ETH_ACCOUNT))
flashbot(w3, FLASHBOTS_SIGNATURE,"https://relay-goerli.flashbots.net/")

print(f"account {ETH_ACCOUNT.address}: {w3.eth.get_balance(ETH_ACCOUNT.address)} wei")

def get_gas_price():
    gas_api = 'https://ethgasstation.info/json/ethgasAPI.json'
    response = requests.get(gas_api).json()

    gas_multiplier = 10
    gas_price_gwei = math.floor(response["fastest"] / 10 * gas_multiplier)
    gas_price = w3.toWei(gas_price_gwei, 'gwei')
    return gas_price

print(get_gas_price())

# create a transaction
tx: TxParams = {
    "from": ETH_ACCOUNT.address,
    "to": w3.toChecksumAddress(SEND_TO),
    "value": w3.toWei("1.0", "gwei"),
    "gasPrice": get_gas_price(),
    "nonce": w3.eth.get_transaction_count(ETH_ACCOUNT.address),
}
tx["gas"] = math.floor(w3.eth.estimate_gas(tx) * 1.2)
signed_tx = ETH_ACCOUNT.sign_transaction(tx)
print(f'created transasction {signed_tx.hash.hex()}')
print(tx)
tx2: TxParams = {
    "to": ETH_ACCOUNT.address,
    "value": Web3.toWei(0.2, "ether"),
    "gas": 25000,
    "maxFeePerGas": Web3.toWei(200, "gwei"),
    "maxPriorityFeePerGas": Web3.toWei(50, "gwei"),
    "nonce": w3.eth.get_transaction_count(ETH_ACCOUNT.address) + 1,
    "chainId": 5,
    "type": 2,
}
tx2["gas"] = math.floor(w3.eth.estimate_gas(tx2) * 1.2)
signed_tx2 = ETH_ACCOUNT.sign_transaction(tx2)
bundle = [
    {"signed_transaction": signed_tx.rawTransaction},
    {"signed_transaction": signed_tx2.rawTransaction}
    # you can include other transactions in the bundle
    # in the order that you want them in the block
]
# flashbots bundles target a specific block, so we target
# any one of the next 3 blocks by emitting 3 bundles

block_number = w3.eth.block_number
print(block_number)
w3.flashbots.send_bundle(bundle, target_block_number=block_number+100)
print(f'bundle broadcasted at block {block_number}')
# wait for the transaction to get mined
tx_id = signed_tx.hash
while (True):
    try:
        w3.eth.wait_for_transaction_receipt(
            tx_id, timeout=1, poll_latency=0.1
        )
        break

    except exceptions.TimeExhausted:
        print(w3.eth.block_number)
        if w3.eth.block_number >= (block_number +3):
            print("ERROR: transaction was not mined")
            exit(1)

print(f'transaction confirmed at block {w3.eth.block_number}: {tx_id.hex()}')
请先 登录 后评论

1 个回答

James
请先 登录 后评论
  • 1 关注
  • 0 收藏,2265 浏览
  • ms666 提出于 2022-06-26 12:15