[solved] Python event error

this code gives the following error can anyone help?

api_key = "apikey"
params = {
    "address": "0xc35DADB65012eC5796536bD9864eD8773aBc74C4",
    "topic": "0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9",
    "chain": "arbitrum",
    "from_block": 0,
    "to_block": 0,
    "from_date": "",
    "to_date": "",
    "offset": 0,
    "limit": 1
}
body = '{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Transfer","type":"event"}'

result = evm_api.events.get_contract_events(
    api_key=api_key,
    params=params,
    body=body,
)

print(result)

error:

Traceback (most recent call last):
  File "/Users/talha/Desktop/pythonbotlar/mysniperbot/sniperV4.py", line 296, in <module>
    result = evm_api.events.get_contract_events(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/moralis/evm_api/events/get_contract_events.py", line 10, in get_contract_events
    api_response = api_instance.get_contract_events(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openapi_evm_api/paths/address_events/post.py", line 557, in get_contract_events
    return self._get_contract_events_oapg(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openapi_evm_api/paths/address_events/post.py", line 451, in _get_contract_events_oapg
    serialized_data = request_body_body.serialize(body, content_type)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openapi_evm_api/api_client.py", line 1488, in serialize
    cast_in_data = media_type.schema(in_data)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openapi_evm_api/schemas.py", line 2439, in __new__
    return super().__new__(cls, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openapi_evm_api/schemas.py", line 530, in __new__
    __path_to_schemas = cls.__get_new_cls(__arg, __validation_metadata)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openapi_evm_api/schemas.py", line 398, in __get_new_cls
    other_path_to_schemas = cls._validate_oapg(arg, validation_metadata=validation_metadata)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openapi_evm_api/schemas.py", line 1654, in _validate_oapg
    _path_to_schemas = super()._validate_oapg(arg, validation_metadata=validation_metadata)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openapi_evm_api/schemas.py", line 337, in _validate_oapg
    raise cls.__get_type_error(
openapi_evm_api.exceptions.ApiTypeError: Invalid type. Required value type is frozendict and passed type was str at ['args[0]']

Hello, I will take a look

1 Like

you can try this code:

from moralis import evm_api
import json

api_key = "API_KEY_HERE"
params = {
    "address": "0xc35DADB65012eC5796536bD9864eD8773aBc74C4",
    "topic": "0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9",
    "chain": "arbitrum",
    "limit": 1
}
body = '{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Transfer","type":"event"}'
body = json.loads(body)

result = evm_api.events.get_contract_events(
    api_key=api_key,
    params=params,
    body=body,
)

print(json.dumps(result, indent=4))

=>

{
    "total": 4088,
    "page": 0,
    "page_size": 1,
    "result": [
        {
            "transaction_hash": "0xfc8ad5b4f0796a9b29ca33db4cdf9059c5cda0e05b2991af1f019f8aced26a42",
            "address": "0xc35dadb65012ec5796536bd9864ed8773abc74c4",
            "block_timestamp": "2023-01-30T13:20:46.000Z",
            "block_number": "56636938",
            "block_hash": "0xff4d14e4a5893d40925e3a1658178cd0a32881c7f1c914c2dee5ea7cd62df236",
            "data": {
                "from": "0x624bc248bd2c4d8ac7644f68e528ac5cc5ce57e2",
                "to": "0xc3911ac1121e32cbb9e94bc897c7a60f915b8547",
                "amount": "209821091227911274859701992036307171136383095156"
            }
        }
    ]
}
1 Like

you can also use streams API for even syncs:

it worked thank you very much but I can’t pull resulting pair address. Can you help me on how to pull the pair address?

can you give an exact example? what pair address you want to extract from that transaction?