web3dart
web3dart copied to clipboard
Error in Web3Client.pendingTransactions
The method seems to have some bug...
Code:
var stream = client.pendingTransactions();
stream.listen((event) {
print(event);
});
Error output:
[VERBOSE-2:ui_dart_state.cc(186)] Unhandled Exception: RPCError: got code -32601 with msg "The method eth_newPendingTransactionFilter does not exist/is not available".
#0 JsonRPC.call
package:web3dart/json_rpc.dart:49
<asynchronous suspension>
#1 _FilterEngine._registerToAPI
package:web3dart/…/core/filters.dart:275
<asynchronous suspension>
[VERBOSE-2:ui_dart_state.cc(186)] Unhandled Exception: RPCError: got code -32000 with msg "filter not found".
#0 JsonRPC.call
package:web3dart/json_rpc.dart:49
<asynchronous suspension>
#1 _FilterEngine.uninstall
package:web3dart/…/core/filters.dart:359
<asynchronous suspension>
Which node server are you using? The method does exist, but you need to use a WebSocket to use it on Infura.
Yes, I have used websocket connecting to Infura on Rinkeby testnet.
Web3({this.privateKey, this.apiURL, this.wsURL, this.contract}) {
client = Web3Client(this.apiURL, Client(), socketConnector: () {
return IOWebSocketChannel.connect(wsURL).cast<String>();
});
}
final web3 = Web3(
privateKey: privateKey,
apiURL: params.httpURL,
wsURL: params.wsURL,
contract: deployedContract);
params['rinkeby'] = AppConfigParams(
"https://rinkeby.infura.io/v3/ff6a249a74e048f1b413cba715f98d07",
"wss://rinkeby.infura.io/ws/v3/ff6a249a74e048f1b413cba715f98d07",
"0xa8d4452ae282fc13521c6a4d91fe58bb49719eb4");
I notice a few things: From the infura docs: // newPendingTransactions
{"jsonrpc":"2.0", "id": 1, "method": "eth_subscribe", "params": ["newPendingTransactions"]}
This should be requested over streamRpcPeer in client.dart file (becuase it is necessary to use websocket ), the method is actually called "eth_subscribe".
_streamRpcPeer!.sendRequest( 'eth_subscribe', [ 'newPendingTransactions' ] ); I also notice that _connectWithPeer() method is not called in that file and therefore streamRpcPeer is not initialize and registerMethod('eth_subscription') either.
If you register that method and do the request by yourself it works, I guess handlePubSubNotification is doing something else trying to handle filters which as far as I now in API v3 is only through websocket and subscriptions.
Final note, newPendingTransaction fetch all the transactions that are send by that node, for manage your transactions is better to use getTransactionReceipt and getTransactionByHash