TransWikia.com

Nethereum C# FilterInput.GetAllChanges always empty

Ethereum Asked by ExaltedOil on February 12, 2021

I use Nethereum in my project to get all pending transactions on a specific smartcontract address. To do that based on the existing docs and Nethereum playground I try the following:

private async Task MonitorPendingTransactions()
{
    var web = new Web3Geth("http://***.***.***.***:8545");
    var transferEventHandler = web3.Eth.GetEvent<TransferEventDTO>(contractAddr);
    var filterAllTransferEventsForContract = transferEventHandler.CreateFilterInput();
    var allTransferEventsForContract = await transferEventHandler.GetAllChanges(filterAllTransferEventsForContract);
    Thread.Sleep(10000);
    allTransferEventsForContract = await transferEventHandler.GetAllChanges(filterAllTransferEventsForContract);
}

My TransferEventDTO is the same as in the official docs in the same place:

[Event("Transfer")]
public class TransferEventDTO : IEventDTO
{
    [Parameter("address", "_from", 1, true)]
    public string From { get; set; }

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

    [Parameter("uint256", "_value", 3, false)]
    public BigInteger Value { get; set; }
}

So far i have 2 issue:

  1. I cant specify the starting block from which i’d like to get output, like pending instead of latest
  2. GetAllChanges() always returns 0 objects, no matter how long i wait, am I doing something wrong in filter configuration or pending transactions should be queried via some other way?

One Answer

Can you change to use Web3? Please refer to my code!

   var _web3 = new Web3("https://ropsten.infura.io/v3/APIKEY");
        var _transactionRpcResult = _web3.Eth.Transactions.GetTransactionByHash.SendRequestAsync("0x02fca948c467b0247030d12f4e1bb6811a626f5b55013d3dbec10cea82f72110");
        var blockNumberResult = _web3.Eth.Blocks.GetBlockNumber.SendRequestAsync();
        blockNumberResult.Wait();
        ulong _currentblockNumber = (ulong)blockNumberResult.Result.Value;
        var transferEventHandler = _web3.Eth.GetEvent<TransferEventDTO>("0xfc420e5a883d3b08ab1fd8299a9fcc18cab74527");
        var filter = transferEventHandler.CreateFilterInput(fromBlock: new BlockParameter(_transactionRpcResult.Result.BlockNumber), toBlock: new BlockParameter(_currentblockNumber));
        var logsresult = transferEventHandler.GetAllChanges(filter);
        logsresult.Wait();
        var logs = logsresult.Result;

TransferEventDTO

[Event("Transfer")]
public class TransferEventDTO : IEventDTO
{
    [Parameter("address", "_from", 1, true)]
    public string From { get; set; }

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

    [Parameter("uint256", "_value", 3, false)]
    public BigInteger Value { get; set; }
}

Answered by Hu Kenneth on February 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP