Skip to content

Commit 72d1592

Browse files
committed
Add abi attribute for ContractFunction
1 parent cdd2afa commit 72d1592

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

newsfragments/3626.feature.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add abi property stateMutability to the ``ContractFunction`` object as ``state_mutability``.

tests/core/contracts/test_contract_example.py

+5
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ def test_updating_greeting_emits_event(w3, foo_contract):
112112
assert event.args._bar == "testing contracts is easy"
113113

114114

115+
def test_abi_state_mutability(w3, foo_contract):
116+
assert foo_contract.functions.setBar.state_mutability == "nonpayable"
117+
assert foo_contract.functions.bar.state_mutability == "view"
118+
119+
115120
@pytest.fixture
116121
def async_eth_tester():
117122
return AsyncEthereumTesterProvider().ethereum_tester

web3/contract/base_contract.py

+6
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,12 @@ def __init__(self, abi: Optional[ABIFunction] = None) -> None:
596596
self.argument_names = tuple([input.get("name", None) for input in event_inputs])
597597
self.argument_types = tuple([input["type"] for input in event_inputs])
598598

599+
@property
600+
def state_mutability(self) -> Optional[str]:
601+
if self.abi is None:
602+
return None
603+
return self.abi.get("stateMutability")
604+
599605
@combomethod
600606
def _get_abi(cls) -> ABIFunction:
601607
if not cls.args and not cls.kwargs:

0 commit comments

Comments
 (0)