Closed avoiney-ledger closed 2 weeks ago
There are new types for ABIs available in ethereum/eth-typing for this purpose. You can get around this by using the new types and casting your ABI
to the new type.
from eth_typing import ABI
abi: ABI = { ... }
c: Contract = w3.eth.contract(
address="0x48C7f48622a2C31FC72B326332cF1e2357C8EF30", abi=abi
)
for el_abi in cast(ABI, c.abi):
if el_abi["type"] == "error":
print(
f"Error: {el_abi['name']}({', '.join([arg['name'] for arg in el_abi['inputs']])})"
)
Using ABI
from web3.typing
will show a type error when referencing the "error"
type on an ABIFunction
.
Non-overlapping equality check (left operand type: "Literal['fallback', 'receive']", right operand type: "Literal['error']")Mypy[comparison-overlap](https://mypy.readthedocs.io/en/latest/_refs.html#code-comparison-overlap)
(variable) el_abi: Any | ABIFunction | ABIEvent
We could add "error"
as a valid ABIFunction
type in web3.types
to mitigate the typing error. Do you agree with adding that @kclowes @fselmo @pacrob ?
Following up, web3.types
will not be updated to include the "error"
Literal on the ABIFunction
type
. ABIError
is preferred.
Ok thanks for this detailed answer!
@avoiney-ledger sorry for the back and forth, I had another chat with the team and we'll implement the error type in the web3.types
module in v6. Instead of adding "error"
to the ABIFunction
type, we decided to add ABIError
as a type and it will be added as another valid ABIElement
. Look for that in the next v6
release!
So cool thanks! I will look forward for it!
What feature should we add?
Some ABI, like the one for smart contract 0x48C7f48622a2C31FC72B326332cF1e2357C8EF30, fetched using Etherscan API, contains the defined errors objects. So the JSON abi contains this: