AnvilSyncSendMiddleware

Documentation for eth_defi.middleware.AnvilSyncSendMiddleware Python class.

class AnvilSyncSendMiddleware

Bases: web3.middleware.base.Web3Middleware

Return from a transaction send only once Anvil has mined the transaction.

Anvil 1.8 automines asynchronously: eth_sendRawTransaction and eth_sendTransaction return the hash before the block exists, so the first receipt poll misses and every receipt wait sleeps one poll interval, one second in our confirmation helpers.

  • eth_sendRawTransaction goes through the EIP-7966 eth_sendRawTransactionSync method, which Anvil answers with the receipt once the transaction is mined. The middleware returns the hash, as the plain method would.

  • eth_sendTransaction is sent as is, because Anvil’s eth_sendTransactionSync takes no timeout and waits 30 s for a transaction that cannot be mined. The middleware then polls the receipt every ANVIL_SYNC_SEND_POLL_SECONDS before returning.

  • Both wait at most ANVIL_SYNC_SEND_TIMEOUT_MS, then return the hash, so tests that mine on demand keep working.

  • On an Anvil without the sync method, raw sends fall back to the plain method for the rest of the connection’s life.

  • Other errors, such as a nonce or gas error, are passed through unchanged.

Callers see no API change; their first receipt read succeeds.

Installed by eth_defi.provider.multi_provider.create_multi_provider_web3() for Anvil connections only. It must be the innermost middleware, so that the signing middleware’s eth_sendRawTransaction also goes through it.

Methods summary

__init__(w3)

async_request_processor(method, params)

async_response_processor(method, response)

async_wrap_make_batch_request(make_batch_request)

async_wrap_make_request(make_request)

request_processor(method, params)

response_processor(method, response)

wrap_make_batch_request(make_batch_request)

wrap_make_request(make_request)

__init__(w3)
Parameters

w3 (web3.main.Web3) –