Eth_subscribe not returning all data for a swap{} transaction

I am trying to monitor contract events with the topic swap{} keccak hash: “0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef

I can successfully connect to the websocket filter and I am getting messages whenever this event fires on a contract address.

Problem is, the [‘data’] variable I get back in the message seems to be missing part of the expected message.

Recieved log:   'data': '0x00000000000000000000000000000000000000000000005411a685c98ef94747'
Expected log (from etherscan): 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002dcbf4840eca000000000000000000000000000000000000000000000000005411a685c98ef947470000000000000000000000000000000000000000000000000000000000000000

As you can see, there is a whole section of the data missing in the reply. The data translates to the following information:
* amount0In :0
* amount1In :3300000000000000000
* amount0Out :1550798353237114701639
* amount1Out :0

Currently, the message I get only gives me only amount0, and I need both amount0 and amount1 for my use case

Raw data from the websocket response:
{"jsonrpc":"2.0","method":"eth_subscription","params":{"subscription":"0x1feed340d52bba03e5ee349f34f56a6b","result":{"removed":false,"logIndex":"0xfb","transactionIndex":"0x37","transactionHash":"0x51ee25d2035041d5b1a3badea9d466781fbdf24cbf5c056d4d01cc202b72c6a4","blockHash":"0xce8ca6baee336d3ee59a796c61eeb0125f5a623dbb1f4c20a15f3dfd0d142825","blockNumber":"0xa48b66","address":"0x56d811088235F11C8920698a204A5010a788f4b3","data":"0x00000000000000000000000000000000000000000000005411a685c98ef94747","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x000000000000000000000000b9b752f7f4a4680eeb327ffe728f46666763a796","0x0000000000000000000000005ce1fd9e8d7aba85dd43079606fedfa4385b06b8"]}}}

I am using python to make the websocket calls, with no special web3 library.

How can I get the entire length of data? Is infura restricting/limiting the amount of bytes it sends back in the ‘data’ field?

Hi @ub5zNq8N_ub5zNq8N - welcome to the Infura community! Can you send over the code you’re using to get this message? That’ll help us troubleshoot.

import websocket
import json
import ssl
import thread
import time
infura_wss="wss://mainnet.infura.io/ws/v3/keyhere"

def on_open(ws):
        ws.send(json.dumps({
                    "jsonrpc": "2.0",
                    "id": 2,
                    "method": "eth_subscribe",
                    "params": ["logs",
                              {"address": ["0x56d811088235F11C8920698a204A5010a788f4b3"],
                              "topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]
                              }]
                }))

def on_error(ws, error):
    print(error)

def on_close(ws):
    print("### closed ###")

def on_message(ws, message):
    print(message)

ws = websocket.WebSocketApp(infura_wss_address,
                          on_message = on_message,
                          on_error = on_error,
                          on_close = on_close)
ws.on_open = on_open
ws.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE})

The message response is not being processed, I am only printing the raw data sent from Infura within Python. It seems to me Infura is not sending the entire log:

Example message print:
{"jsonrpc":"2.0","method":"eth_subscription","params":{"subscription":"0x1feed340d52bba03e5ee349f34f56a6b","result":{"removed":false,"logIndex":"0xfb","transactionIndex":"0x37","transactionHash":"0x51ee25d2035041d5b1a3badea9d466781fbdf24cbf5c056d4d01cc202b72c6a4","blockHash":"0xce8ca6baee336d3ee59a796c61eeb0125f5a623dbb1f4c20a15f3dfd0d142825","blockNumber":"0xa48b66","address":"0x56d811088235F11C8920698a204A5010a788f4b3","data":"0x00000000000000000000000000000000000000000000005411a685c98ef94747","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x000000000000000000000000b9b752f7f4a4680eeb327ffe728f46666763a796","0x0000000000000000000000005ce1fd9e8d7aba85dd43079606fedfa4385b06b8"]}}}

In the message, this is the data that we received:
“data”:“0x00000000000000000000000000000000000000000000005411a685c98ef94747

But I am expecting a larger byte string:
0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002dcbf4840eca000000000000000000000000000000000000000000000000005411a685c98ef947470000000000000000000000000000000000000000000000000000000000000000

You can see the associated data in the log on etherscan at this link (the last one, #253):
https://etherscan.io/tx/0x51ee25d2035041d5b1a3badea9d466781fbdf24cbf5c056d4d01cc202b72c6a4#eventlog

Hi @ub5zNq8N_ub5zNq8N,

I think the issue is that you are specifying the Transfer topic in your subscription (0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef) and not the Swap event (0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822 ) so the response you got is for log number 251 (0xfb) on the same etherscan page, not for 253 (0xfd).

To correct this issue in on_open change the topics parameter to "0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822"

Thanks,
Ryan

Thank you! Looks like my wires were crossed…I had to do 2 things, change the hash, as you stated…

and also change the address to the correct contract address.

Really appreciate the help.