xclud / web3dart

Ethereum library, written in Dart.
https://pub.dev/packages/web3dart
MIT License
183 stars 96 forks source link

get transaction status in real time #52

Closed omarmoukiAtechy closed 2 years ago

omarmoukiAtechy commented 2 years ago

is this package supports transaction subscription? same as web3.eth.subscribe in web3.js if it already supports it, how can I implement it. and if not, is there a workaround?

mrtnetwork commented 2 years ago

Using pendingTransactions method, you can receive all pending transactions with the stream If you want to track a specific transaction whether it has been confirmed or not you can use Timer.periodic to check your transaction every second with getTransactionByHash (This method is mostly executed when your transaction is pending, and you will notice that the transaction is in the network, or it is pending or there is an error) or getTransactionReceipt ( This method works only when your transaction is in the block ), You can also use addedBlocks method instead of a timer, this will give you a stream and inform you when new block created, you can track your transaction with the above methods when you receive new block message

omarmoukiAtechy commented 2 years ago

thank you for your explanation, but I don't why the pendingTransactions returns an error. the error is RPCError (RPCError: got code -32601 with msg "The method eth_newPendingTransactionFilter does not exist/is not available".) and my code is:

 void initialSetup() {
    httpClient = http.Client();
    // String url = "https://rinkeby.infura.io/v3/" + (dotenv.env['PROJECT_ID'] ?? "");
    String url = "https://rinkeby.infura.io/v3/" +
        (dotenv.env[AppStrings.Env_CONTRACT_PROJECT_ID]!);
    rpc = JsonRPC(url, httpClient);
    ethClient = Web3Client.custom(rpc, socketConnector: () {
      return IOWebSocketChannel.connect(
              "wss://rinkeby.infura.io/ws/v3/${dotenv.env[AppStrings.Env_CONTRACT_PROJECT_ID]!}/")
          .cast<String>();
    });
  }
 ethClient.pendingTransactions().listen((event) {
      log(event);
    });

I don't know if I am doing something wrong or there's an error with the package

mrtnetwork commented 2 years ago

when you get an error like filter or method doest not exist its related to your rpc url most more RPC URL doest not work with stream or filterChanged like infura, use moralis api

omarmoukiAtechy commented 2 years ago

Thank you very much that was super helpful.