@@ -537,6 +537,7 @@ Signing
537537~~~~~~~
538538
539539.. py :method :: web3.middleware.construct_sign_and_send_raw_middleware(private_key_or_account)
540+ web3.middleware.async_construct_sign_and_send_raw_middleware(private_key_or_account)
540541
541542 This middleware automatically captures transactions, signs them, and sends them as raw transactions.
542543The ``from `` field on the transaction, or ``w3.eth.default_account `` must be set to the address of the private key for
@@ -573,6 +574,27 @@ this middleware to have any effect.
573574 >> > w3.middleware_onion.add(construct_sign_and_send_raw_middleware(acct))
574575 >> > w3.eth.default_account = acct.address
575576
577+ >> > # use `eth_sendTransaction` to automatically sign and send the raw transaction
578+ >> > w3.eth.send_transaction(tx_dict)
579+ HexBytes(' 0x09511acf75918fd03de58141d2fd409af4fd6d3dce48eb3aa1656c8f3c2c5c21' )
580+
581+ Similarly, with AsyncWeb3:
582+
583+ .. code-block :: python
584+
585+ >> > from web3 import AsyncWeb3
586+ >> > async_w3 = AsyncWeb3(AsyncHTTPProvider(' HTTP_ENDPOINT' ))
587+ >> > from web3.middleware import async_construct_sign_and_send_raw_middleware
588+ >> > from eth_account import Account
589+ >> > import os
590+ >> > acct = async_w3.eth.account.from_key(os.environ.get(' PRIVATE_KEY' ))
591+ >> > async_w3.middleware_onion.add(await async_construct_sign_and_send_raw_middleware(acct))
592+ >> > async_w3.eth.default_account = acct.address
593+
594+ >> > # use `eth_sendTransaction` to automatically sign and send the raw transaction
595+ >> > await async_w3.eth.send_transaction(tx_dict)
596+ HexBytes(' 0x09511acf75918fd03de58141d2fd409af4fd6d3dce48eb3aa1656c8f3c2c5c21' )
597+
576598 Now you can send a transaction from acct.address without having to build and sign each raw transaction.
577599
578600When making use of this signing middleware, when sending dynamic fee transactions (recommended over legacy transactions),
0 commit comments