Nethereum: Event DTO doesn't work in 3.X

I was using nethereum 2.4.0 for a long time and it worked as expected. But for several reasons, e.g. bug fixes, I bumped the version for the latest one.

I have following event.

event RequestCreated(bytes30 indexed serviceNumber, uint64 index);

And I had following DTO:

    public class RequestCreatedEventDto
    {
        [Parameter(ByteString.ServiceNumberSolidityType, "serviceNumber", 1, true)]
        public byte[] ServiceNumber { get; set; }

        [Parameter("int", "index", 2)]
        [UsedImplicitly]
        public int Index { get; set; }
    }

After update I tried to use it but it said “Class cannot be used as event DTO”. So I googled a bit and I found you added EventAttribute for it. Okay, no problemo:

    [Event("RequestCreated")]
    public class RequestCreatedEventDto
    {
        [Parameter(ByteString.ServiceNumberSolidityType, "serviceNumber", 1, true)]
        public byte[] ServiceNumber { get; set; }

        [Parameter("int", "index", 2)]
        [UsedImplicitly]
        public int Index { get; set; }
    }

I run, but it doesn’t work. I debugged nethereum and I see that it’s Sha3Signature doesn’t match signature of the first topic. I.e. this check doesn’t pass:

public static bool IsLogForEvent(this FilterLog log, string signature)
{
	if (log.Topics != null && log.Topics.Length > 0)
	{
		var eventtopic = log.Topics[0].ToString();
		if (signature.IsTheSameHex(eventtopic))
			return true;
	}
	return false;
}

I tried different names, but they don’t work.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 22 (22 by maintainers)

Most upvoted comments

Ok I think the Index is a “uint64” not an “int”

Ok ill expand it further to include why the signatures don’t match.

Right. It was working before so I didn’t spot that signature doesn’t exactly match. Maybe add the note to the exception?

Ill create some sample for you with all variations.

IEventDTO is a generic interface that allows to extend all Event DTOs with extension methods without having to rely on subclasses. The new docs include this: https://nethereum.readthedocs.io/en/latest/nethereum-events-gettingstarted/#contract-filters-and-event-logs Also the it was listed on Breaking changes https://github.com/Nethereum/Nethereum/releases/tag/3.0.0. Which I tried to keep them to a minimun.