[SOLVED] Moralis Stream notifies me on every topic, not just specified one

Hi! I’m new to Moralis Streams, it looks really great, but I cannot uderstand one thing. When I register a stream, and then update it with ABI and specify the event (topic) on which to update, I’m getting updated on all events, and in the payload I don’t even see the info which event triggered this notification. Am I doing something wrong?

    const ABI = [
			{
				"anonymous": false,
				"inputs": [
					{ "indexed": true, "internalType": "bytes32", "name": "role", "type": "bytes32" },
					{ "indexed": true, "internalType": "address", "name": "account", "type": "address" },
					{ "indexed": true, "internalType": "address", "name": "sender", "type": "address" }
				],
				"name": "SomeEvent",
				"type": "event"
			},
		];

    const response = await Moralis.Streams.update({
        id: "78893459-1a28-44bb-8215-77f69c826209",
        abi: ABI,
        includeContractLogs: true,
        topic0: ["SomeEvent(bytes32, address, address)"],
        description: "My first stream updated",
    });

Hi @pavopa

By any chance did you set the Native transactions option of stream as true?
When this it is selected you will receive webhooks for all the transactions.

If you want to get webhooks for only the event you should select the Contract Interactions option and remove the Native transactions option

2 Likes

Thank you @johnversus! You’re correct. The only downside I see is the missing txs details when Native Transactions is disabled. Additionally - is there a way to distinguish the contract interaction (topic) that triggered the event? I don’t see this info in the event body. E.g. I’m selecting two topics that should trigger the event. How to know from the body of the stream which was it?

You will have to hardcode the topic0 hashes in your code to compare and identify the event type in webhook data. As of now, this is the only way to distinguish between the events.

In the future we are planning to add the topic names in the webhook data for easy identification.

You can also use the getTransactionVerbose API endpoint directly in your backend to read the transaction data.
The tx record received in webhook will cost you 15CU but using it through API will cost you 5CU. :smiley:

1 Like

Thank you @johnversus, this is gold. Btw, I don’t need to hardcode, because getTransactionVerbose shows a decoded event :rocket:

1 Like