Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/providers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ Eth
- :meth:`web3.eth.get_transaction() <web3.eth.Eth.get_transaction>`
- :meth:`web3.eth.get_transaction_count() <web3.eth.Eth.get_transaction_count>`
- :meth:`web3.eth.send_transaction() <web3.eth.Eth.send_transaction>`
- :meth:`web3.eth.send_raw_transaction() <web3.eth.Eth.send_raw_transaction>`

Net
***
Expand Down
1 change: 1 addition & 0 deletions newsfragments/2135.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update AsyncHTTPProvider doc Supported Methods to include ``web3.eth.send_raw_transaction()``.
1 change: 1 addition & 0 deletions newsfragments/2135.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add async ``eth.send_raw_transaction`` method
42 changes: 20 additions & 22 deletions web3/_utils/module_testing/eth_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
TYPE_CHECKING,
Callable,
Sequence,
Union,
cast,
)

Expand Down Expand Up @@ -262,6 +261,18 @@ async def test_eth_send_transaction_max_fee_less_than_tip(
):
await async_w3.eth.send_transaction(txn_params) # type: ignore

@pytest.mark.asyncio
async def test_eth_send_raw_transaction(self, async_w3: "Web3") -> None:
# private key 0x3c2ab4e8f17a7dea191b8c991522660126d681039509dc3bb31af7c9bdb63518
# This is an unfunded account, but the transaction has a 0 gas price, so is valid.
# It never needs to be mined, we just want the transaction hash back to confirm.
# tx = {'to': '0x0000000000000000000000000000000000000000', 'value': 0, 'nonce': 1, 'gas': 21000, 'gasPrice': 0, 'chainId': 131277322940537} # noqa: E501
# NOTE: nonce=1 to make txn unique from the non-async version of this test
raw_txn = HexBytes('0xf8650180825208940000000000000000000000000000000000000000808086eecac466e115a0ffdd42d7dee4ac85427468bc616812e49432e285e4e8f5cd9381163ac3b28108a04ec6b0d89ecbd5e89b0399f336ad50f283fafd70e86593250bf5a2adfb93d17e') # noqa: E501
expected_hash = HexStr('0x52b0ff9cb472f25872fa8ec6a62fa59454fc2ae7901cfcc6cc89d096f49b8fc1')
txn_hash = await async_w3.eth.send_raw_transaction(raw_txn) # type: ignore
assert txn_hash == async_w3.toBytes(hexstr=expected_hash)

@pytest.mark.asyncio
async def test_gas_price_strategy_middleware(
self, async_w3: "Web3", unlocked_account_dual_type: ChecksumAddress
Expand Down Expand Up @@ -1887,27 +1898,14 @@ def test_eth_modifyTransaction_deprecated(
assert modified_txn['gas'] == 21000
assert modified_txn['gasPrice'] == cast(int, txn_params['gasPrice']) * 2

@pytest.mark.parametrize(
'raw_transaction, expected_hash',
[
(
# private key 0x3c2ab4e8f17a7dea191b8c991522660126d681039509dc3bb31af7c9bdb63518
# This is an unfunded account, but the transaction has a 0 gas price, so is valid.
# It never needs to be mined, we just want the transaction hash back to confirm.
# tx = {'to': '0x0000000000000000000000000000000000000000', 'value': 0, 'nonce': 0, 'gas': 21000, 'gasPrice': 0, 'chainId': 131277322940537} # noqa: E501
HexBytes('0xf8658080825208940000000000000000000000000000000000000000808086eecac466e115a038176e5f9f1c25ce470ce77856bacbc02dd728ad647bb8b18434ac62c3e8e14fa03279bb3ee1e5202580668ec62b66a7d01355de3d5c4ef18fcfcb88fac56d5f90'), # noqa: E501
'0x6ab943e675003de610b4e94f2e289dc711688df6e150da2bc57bd03811ad0f63',
),
]
)
def test_eth_send_raw_transaction(
self,
web3: "Web3",
raw_transaction: Union[HexStr, bytes],
funded_account_for_raw_txn: ChecksumAddress,
expected_hash: HexStr,
) -> None:
txn_hash = web3.eth.send_raw_transaction(raw_transaction)
def test_eth_send_raw_transaction(self, web3: "Web3") -> None:
# private key 0x3c2ab4e8f17a7dea191b8c991522660126d681039509dc3bb31af7c9bdb63518
# This is an unfunded account, but the transaction has a 0 gas price, so is valid.
# It never needs to be mined, we just want the transaction hash back to confirm.
# tx = {'to': '0x0000000000000000000000000000000000000000', 'value': 0, 'nonce': 0, 'gas': 21000, 'gasPrice': 0, 'chainId': 131277322940537} # noqa: E501
raw_txn = HexBytes('0xf8658080825208940000000000000000000000000000000000000000808086eecac466e115a038176e5f9f1c25ce470ce77856bacbc02dd728ad647bb8b18434ac62c3e8e14fa03279bb3ee1e5202580668ec62b66a7d01355de3d5c4ef18fcfcb88fac56d5f90') # noqa: E501
expected_hash = HexStr('0x6ab943e675003de610b4e94f2e289dc711688df6e150da2bc57bd03811ad0f63')
txn_hash = web3.eth.send_raw_transaction(raw_txn)
assert txn_hash == web3.toBytes(hexstr=expected_hash)

def test_eth_call(
Expand Down
17 changes: 12 additions & 5 deletions web3/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ def send_transaction_munger(self, transaction: TxParams) -> Tuple[TxParams]:
mungers=[send_transaction_munger]
)

_send_raw_transaction: Method[Callable[[Union[HexStr, bytes]], HexBytes]] = Method(
RPC.eth_sendRawTransaction,
mungers=[default_root_munger],
)

_get_transaction: Method[Callable[[_Hash32], TxData]] = Method(
RPC.eth_getTransactionByHash,
mungers=[default_root_munger]
Expand Down Expand Up @@ -270,6 +275,10 @@ async def send_transaction(self, transaction: TxParams) -> HexBytes:
# types ignored b/c mypy conflict with BlockingEth properties
return await self._send_transaction(transaction) # type: ignore

async def send_raw_transaction(self, transaction: Union[HexStr, bytes]) -> HexBytes:
# types ignored b/c mypy conflict with BlockingEth properties
return await self._send_raw_transaction(transaction) # type: ignore

async def get_transaction(self, transaction_hash: _Hash32) -> TxData:
# types ignored b/c mypy conflict with BlockingEth properties
return await self._get_transaction(transaction_hash) # type: ignore
Expand Down Expand Up @@ -685,10 +694,8 @@ def modify_transaction(
def send_transaction(self, transaction: TxParams) -> HexBytes:
return self._send_transaction(transaction)

send_raw_transaction: Method[Callable[[Union[HexStr, bytes]], HexBytes]] = Method(
RPC.eth_sendRawTransaction,
mungers=[default_root_munger],
)
def send_raw_transaction(self, transaction: Union[HexStr, bytes]) -> HexBytes:
return self._send_raw_transaction(transaction)

def sign_munger(
self,
Expand Down Expand Up @@ -878,7 +885,7 @@ def setGasPriceStrategy(self, gas_price_strategy: GasPriceStrategy) -> None:
submitWork = DeprecatedMethod(submit_work, 'submitWork', 'submit_work')
getLogs = DeprecatedMethod(get_logs, 'getLogs', 'get_logs')
estimateGas = DeprecatedMethod(estimate_gas, 'estimateGas', 'estimate_gas') # type: ignore
sendRawTransaction = DeprecatedMethod(send_raw_transaction,
sendRawTransaction = DeprecatedMethod(send_raw_transaction, # type: ignore
'sendRawTransaction',
'send_raw_transaction')
getTransactionReceipt = DeprecatedMethod(get_transaction_receipt,
Expand Down