4

I need to watch changes in blockchain. For web3.js it was simle.

web3.eth.filter('latest').watch(function () {
            //some code
        });

How implement this in Nethereum?

3 Answers 3

4

It seems that from the official doc, that web3.eth.filter is not implemented yet:

We currently have:

Eth, Net, Miner, Admin, Personal and DebugGeth. Eth, Net are as described before generic to the standard Eth and Miner, Admin, Personal and DebugGeth belong to the management RPC.

> web3.Eth.Transactions.GetTransactionReceipt;
> web3.Eth.Transactions.Call; web3.Eth.Transactions.EstimateGas;
> web3.Eth.Transactions.GetTransactionByBlockHashAndIndex;
> web3.Net.PeerCount; web3.Eth.GetBalance; web3.Eth.Mining.IsMining;
> web3.Eth.Accounts;
3
  • Hi this is incorrect, which version of Nethereum are you using? This was one of the first things to be implemented. Commented Feb 1, 2017 at 10:45
  • Hello, I'm not using it, I just read the documentation, from the link above. It seems like it is a bit confusing.... Commented Feb 1, 2017 at 10:59
  • Ah.. Filters are part of the Eth rpc api Commented Feb 1, 2017 at 11:11
6

Nethereum implements Filters. Raw Filters are part of Eth and can be accessed using:

            web3.Eth.Filters.GetFilterChangesForBlockOrTransaction
            web3.Eth.Filters.GetFilterChangesForEthNewFilter
            web3.Eth.Filters.GetFilterLogsForBlockOrTransaction
            web3.Eth.Filters.GetFilterLogsForEthNewFilter
            web3.Eth.Filters.GetLogs
            web3.Eth.Filters.NewBlockFilter
            web3.Eth.Filters.NewFilter
            web3.Eth.Filters.NewPendingTransactionFilter
            web3.Eth.Filters.UninstallFilter 

If you need to create specific filters for contract events you can also do the following:

    var multiplyEvent = contract.GetEvent("Multiplied");
    var filterAll = await multiplyEvent.CreateFilterAsync();
    var filter7 = await multiplyEvent.CreateFilterAsync(7);

The filters used here one is for all "Multiplied" events, and the other is for all events which the first topic is 7.

If you want to retrieve the changes since the filter was created or last called you can do the following:

    var log = await multiplyEvent.GetFilterChanges<MultipliedEvent>(filterAll);
    var log7 = await multiplyEvent.GetFilterChanges<MultipliedEvent>(filter7);

When working with contracts you can use deserialised the output into Event DTOs like in the scenario above is MultipliedEvent

 public class MultipliedEvent
 {
    [Parameter("int", "a", 1, true)]
    public int MultiplicationInput {get; set;}

    [Parameter("address", "sender", 2, true)]
    public string Sender {get; set;}

    [Parameter("int", "result", 3, false)]
    public int Result {get; set;}

 }

For more information on filters and contracts there is a specific topic and video on the documentation

https://nethereum.readthedocs.io/en/latest/contracts/calling-transactions-events/

2

This is a very good explanation by Juan Blanco in my opinion.
Quote from Gitter chat:

There is no catching of events as such everything has a level of polling to get that data even the javascript watch It has not been implemented any watching mechanism as there are many ways to do it.. depending on your set up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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