2

I was trying to get all events from my smart contract (in Ropsten) via Infura node.

The problem is that I know that Infura does no support creating filters, but I don't know how to get events by other way.

This is my method:

def tx_resource_smart_contract_history():
    contract = wb3.eth.contract(
        address=config.audablok_contract_address, abi=get_abi_audablok()
    )
    event_filter = contract.events.SmartContractInfoEvent.createFilter(fromBlock='latest')

    for event in event_filter:
        #Do Something

    return "TRUE"

The console error log is this:

File "/home/ibai/Documentos/proyecto/AudablokAPI/venv/lib/python3.6/site-packages/flask/app.py", line 2328, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/ibai/Documentos/proyecto/AudablokAPI/venv/lib/python3.6/site-packages/flask/app.py", line 2314, in wsgi_app
    response = self.handle_exception(e)
  File "/home/ibai/Documentos/proyecto/AudablokAPI/venv/lib/python3.6/site-packages/flask/app.py", line 1760, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/ibai/Documentos/proyecto/AudablokAPI/venv/lib/python3.6/site-packages/flask/_compat.py", line 36, in reraise
    raise value
  File "/home/ibai/Documentos/proyecto/AudablokAPI/venv/lib/python3.6/site-packages/flask/app.py", line 2311, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/ibai/Documentos/proyecto/AudablokAPI/venv/lib/python3.6/site-packages/flask/app.py", line 1834, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/ibai/Documentos/proyecto/AudablokAPI/venv/lib/python3.6/site-packages/flask/app.py", line 1737, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/ibai/Documentos/proyecto/AudablokAPI/venv/lib/python3.6/site-packages/flask/_compat.py", line 36, in reraise
    raise value
  File "/home/ibai/Documentos/proyecto/AudablokAPI/venv/lib/python3.6/site-packages/flask/app.py", line 1832, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/ibai/Documentos/proyecto/AudablokAPI/venv/lib/python3.6/site-packages/flask/app.py", line 1818, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/ibai/Documentos/proyecto/AudablokAPI/api/dataset.py", line 737, in tx_resource_smart_contract_history
    event_filter = contract.events.SmartContractInfoEvent.createFilter(fromBlock='latest')
  File "/home/ibai/Documentos/proyecto/AudablokAPI/venv/lib/python3.6/site-packages/web3/utils/decorators.py", line 16, in _wrapper
    return self.method(objtype, *args, **kwargs)
  File "/home/ibai/Documentos/proyecto/AudablokAPI/venv/lib/python3.6/site-packages/web3/contract.py", line 1322, in createFilter
    log_filter = self.web3.eth.filter(event_filter_params)
  File "/home/ibai/Documentos/proyecto/AudablokAPI/venv/lib/python3.6/site-packages/web3/eth.py", line 333, in filter
    [filter_params],
  File "/home/ibai/Documentos/proyecto/AudablokAPI/venv/lib/python3.6/site-packages/web3/manager.py", line 112, in request_blocking
    raise ValueError(response["error"])
ValueError: {'code': -32601, 'message': 'The method eth_newFilter does not exist/is not available'}

Does anybody know how could I do this by other way? I mean, how could I get all events from my smart contract?

Thanks very much.

1

You are getting the error The method eth_newFilter does not exist/is not available because you are not using the websocket endpoint from Infura. the eth_newFilter call only exists on websockets.

Change your Infura provider from:

https://mainnet.infura.io/v3/YOUR-PROJECT-ID

to:

wss://mainnet.infura.io/ws/v3/YOUR-PROJECT-ID

|improve this answer|||||
  • I am using ropsten becouse I am still testing my sistem, ¿How could I continue using ropsten without an own node? – Ibai Nov 22 '19 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.