AnvilSyncSendMiddleware
Documentation for eth_defi.middleware.AnvilSyncSendMiddleware Python class.
- class AnvilSyncSendMiddleware
Bases:
web3.middleware.base.Web3MiddlewareReturn from a transaction send only once Anvil has mined the transaction.
Anvil 1.8 automines asynchronously:
eth_sendRawTransactionandeth_sendTransactionreturn 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_sendRawTransactiongoes through the EIP-7966eth_sendRawTransactionSyncmethod, which Anvil answers with the receipt once the transaction is mined. The middleware returns the hash, as the plain method would.eth_sendTransactionis sent as is, because Anvil’seth_sendTransactionSynctakes no timeout and waits 30 s for a transaction that cannot be mined. The middleware then polls the receipt everyANVIL_SYNC_SEND_POLL_SECONDSbefore 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’seth_sendRawTransactionalso 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) –