1

Calling GetBlockWithTransactionsByNumber asynchronoulsy from within a ProcessorForContract frequently returns NULLs. If I execute the following:

HexBigInteger blockNumber = new HexBigInteger(sl.Log.BlockNumber);
blockFromChain = await web3.Eth.Blocks.GetBlockWithTransactionsByNumber.SendRequestAsync(blockNumber);

I very often get a NULL value in blockFromChain but if I select "set next statement" from within the VS debugger and selects the async call again it will indeed return a block. To me it seems that the async call doesn't wait 'til the actual block has been returned. The reason I make a GetBlockWithTransactionsByNumber from within my (Create)ProcessorForContract async method is that I need to get the actual block timestamp as my TransferEventDTO doesn't include a timestamp in the .Log or .Event objects. If there's a better way to get the timestamp I'm all ears :) The async method I'm referring to looks like:

var logsProcessor = web3.Processing.Logs.CreateProcessorForContract<TransferEventDTO>(ContractAddress, (Func<EventLog<TransferEventDTO>, Task>)(async sl =>
{
   HexBigInteger blockNumber = new HexBigInteger(sl.Log.BlockNumber);
   blockFromChain = await web3.Eth.Blocks.GetBlockWithTransactionsByNumber.SendRequestAsync(blockNumber);
   code goes here...
}

The application is a .Net 7 C# console app.

Many thanks in advance!

1 Answer 1

0

the same thing happened to me.

To check if it is a problem with the Nethereum library, I need to create a service that simulates the Web3 library, and I got the same result.
If you use public endpoints from providers like(DRPC, 1RPC, etc.) from time to time you can get responses that have a null value for the result field( {"id":1,"jsonrpc":"2.0","result":null}).

I use .Net Polly library to achieve retry and wait functionality and in most cases, after 1 or 2 retries I get good value for the result field in provider responses.

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.