I have a problem, this transaction with SushiRouter does not work, and it also writes an error ImportError: cannot import name 'encode' from 'eth_abi' (C:\Users\PC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\eth_abi_init_.py)
sushi_abi = json.load(open('router_sushi_abi.json'))
sushi_arbitrum_address = arb_w3.to_checksum_address('0x9c6522117e2ed1fe5bdb72bb0ed5e3f2bde7dbe0')
#sushi_optimism_address = opt_w3.to_checksum_address('0xB0D502E938ed5f4df2E681fE6E419ff29631d62b')
sushi_arbitrum_contract = arb_w3.eth.contract(address=sushi_arbitrum_address, abi=sushi_abi)
def swapRouter(wallet, amount, tokenout):
account = arb_w3.eth.account.from_key(wallet)
address = account.address
nonce = arb_w3.eth.get_transaction_count(address)
value = arb_w3.to_wei(amount, 'ether')
#min_amount = value - (value * 5) // 1000
encoded_eth = eth_abi.encode_single('address', eth_address)
encoded_weth = eth_abi.encode_single('address', weth_address)
encoded_token = eth_abi.encode_single('address', tokenout)
route = encoded_eth + encoded_weth + encoded_token
approve = arb_w3.to_checksum_address('0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE')
swap_txn = sushi_arbitrum_contract.functions.processRoute(eth_adress,value,tokenout, 0 ,address,route).build_transaction({
'from': address,
'value': value,
'gasPrice': arb_w3.eth.gas_price,
'nonce': arb_w3.eth.get_transaction_count(address),
})
signed_swap_txn = arb_w3.eth.account.sign_transaction(swap_txn, wallet)
swap_txn_hash = arb_w3.eth.send_raw_transaction(signed_swap_txn.rawTransaction)
print(f"SUSHI SWAP | TRANS ACCEPTED: https://arbiscan.io/tx/{swap_txn_hash.hex()}")