Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Smart Contract Event problem RPCError: got code -32601 #37

Closed
liuyuejiang opened this issue May 13, 2019 · 2 comments
Closed

Smart Contract Event problem RPCError: got code -32601 #37

liuyuejiang opened this issue May 13, 2019 · 2 comments

Comments

@liuyuejiang
Copy link

liuyuejiang commented May 13, 2019

When deploying the smart contract to Ropsten network, I tried to listen to the events from the contract, however, I got an error.
There's no error when deploying the same smart contract to Ganache.

E/flutter (27128): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: RPCError: got code -32601 with msg "The method eth_newFilter does not exist/is not available".
E/flutter (27128): #0      JsonRPC.call
package:web3dart/json_rpc.dart:49
E/flutter (27128): <asynchronous suspension>
E/flutter (27128): #1      _FilterEngine._registerToAPI
package:web3dart/…/core/filters.dart:232
E/flutter (27128): <asynchronous suspension>
E/flutter (27128): #2      _FilterEngine.addFilter
package:web3dart/…/core/filters.dart:222
E/flutter (27128): #3      Web3Client.events
package:web3dart/…/core/client.dart:328
E/flutter (27128): #4      _DeviceDetailPageState._listenevent
package:iotdevices/pages/detail.dart:62
E/flutter (27128): <asynchronous suspension>
E/flutter (27128): #5      _DeviceDetailPageState.initState
package:iotdevices/pages/detail.dart:125

My listening event dart code is as below:


var privatekey =
    "XXXXX";//Ropsten
final EthereumAddress contractAddr =
    EthereumAddress.fromHex('XXXX);//Ropsten

var apiUrl =
    "https://ropsten.infura.io/v3/XXX"; //Ropsten

var credentials = EthPrivateKey.fromHex(privatekey);

  _listenevent() async {
    String serveraddress = await SharedData.getServerAddress();
    if (serveraddress.length > 5) {
      apiUrl = serveraddress;
    }
    setState(() {
      client = Web3Client(apiUrl, Client());
    });
    
    var contract = await Web3.deployedcontract();
    final colorChangeEvent = contract.event('ColorChange');
    subscription = client
        .events(
            FilterOptions.events(contract: contract, event: colorChangeEvent))
        .take(4)
        .listen((event) {
      final decoded = colorChangeEvent.decodeResults(event.topics, event.data);

      final deviceid = decoded[0] as String;
      final red = decoded[1] as BigInt;
      final green = decoded[2] as BigInt;
      final blue = decoded[3] as BigInt;
      print("event:ID:$deviceid");
      print("event:red:${red.toInt()}");
      print("event:green:${green.toInt()}");
      print("event:blue:${blue.toInt()}");
      var curid = widget.curdevice.bid.toInt().toString();
      if (deviceid.contains(curid)) {
        print("this device changed!");
        var devcolor =
            TransColor.trancolor(red.toInt(), green.toInt(), blue.toInt());
        // print(widget.curdevice.green);
        if (mounted) {
          setState(() {
            currentColor = Color(devcolor);
          });
        }
        Event.eventBus.fire(new DeviceAdd(curdevices.name));
      }
    });
    await subscription.asFuture();
  }

How can I do with that error, is that the problem with https request? Thank you.

@simolus3
Copy link
Owner

Looking at the infura documentation, it seems like they only support event filters over websockets. This library doesn't support the rpc api over websockets (yet), so events sadly can't be used with infura at the time being. That's a bit unfortunate that they don't adhere to the official rpc api :/
I've created the referencing issue to implement websocket support, which I'll hopefully get done this weekend.

@liuyuejiang
Copy link
Author

Looking at the infura documentation, it seems like they only support event filters over websockets. This library doesn't support the rpc api over websockets (yet), so events sadly can't be used with infura at the time being. That's a bit unfortunate that they don't adhere to the official rpc api :/
I've created the referencing issue to implement websocket support, which I'll hopefully get done this weekend.

Thank you very much, wish you can finish this weekend.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants