Skip to main content
Removed useless import
Source Link

I am using eth_subscribe to log for all token transfer events that are happening on the blockchain.

Here is my code:

import asyncio
import json
from secret_config import RPC_ENDPOINT
from websockets import connect

from time import sleep

async def get_event():
    print("Started loop")
    async with connect(RPC_ENDPOINT) as ws:
        await ws.send('{"id": 1, "method": "eth_subscribe", "params": ["logs", {"topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}]}')
        subscription_response = await ws.recv()
        print(subscription_response)
        # you are now subscribed to the event 
        # you keep trying to listen to new events (similar idea to longPolling)
        while True:
            try:
                message = await asyncio.wait_for(ws.recv(), timeout=60)
                data = json.loads(message)
                result = data["params"]["result"]
                print(f"token address: {result['address']}, block: {int(result['blockNumber'], 16)}, tr_hash: {result['transactionHash']}")
                pass
            except:
                pass

if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    while True:
        loop.run_until_complete(get_event())

My question is: Is it 100% sure that the events will come in the right order of execution?

Or it is possible that sometimes, the events are not sent in the right order? I am planning to run this code on all EVM blockchains.

I am using eth_subscribe to log for all token transfer events that are happening on the blockchain.

Here is my code:

import asyncio
import json
from secret_config import RPC_ENDPOINT
from websockets import connect

from time import sleep

async def get_event():
    print("Started loop")
    async with connect(RPC_ENDPOINT) as ws:
        await ws.send('{"id": 1, "method": "eth_subscribe", "params": ["logs", {"topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}]}')
        subscription_response = await ws.recv()
        print(subscription_response)
        # you are now subscribed to the event 
        # you keep trying to listen to new events (similar idea to longPolling)
        while True:
            try:
                message = await asyncio.wait_for(ws.recv(), timeout=60)
                data = json.loads(message)
                result = data["params"]["result"]
                print(f"token address: {result['address']}, block: {int(result['blockNumber'], 16)}, tr_hash: {result['transactionHash']}")
                pass
            except:
                pass

if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    while True:
        loop.run_until_complete(get_event())

My question is: Is it 100% sure that the events will come in the right order of execution?

Or it is possible that sometimes, the events are not sent in the right order? I am planning to run this code on all EVM blockchains.

I am using eth_subscribe to log for all token transfer events that are happening on the blockchain.

Here is my code:

import asyncio
import json
from secret_config import RPC_ENDPOINT
from websockets import connect

async def get_event():
    print("Started loop")
    async with connect(RPC_ENDPOINT) as ws:
        await ws.send('{"id": 1, "method": "eth_subscribe", "params": ["logs", {"topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}]}')
        subscription_response = await ws.recv()
        print(subscription_response)
        # you are now subscribed to the event 
        # you keep trying to listen to new events (similar idea to longPolling)
        while True:
            try:
                message = await asyncio.wait_for(ws.recv(), timeout=60)
                data = json.loads(message)
                result = data["params"]["result"]
                print(f"token address: {result['address']}, block: {int(result['blockNumber'], 16)}, tr_hash: {result['transactionHash']}")
                pass
            except:
                pass

if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    while True:
        loop.run_until_complete(get_event())

My question is: Is it 100% sure that the events will come in the right order of execution?

Or it is possible that sometimes, the events are not sent in the right order? I am planning to run this code on all EVM blockchains.

added 1 character in body
Source Link

I am using eth_subscribe to log for all token transfer events that are happening on the blockchain.

Here is my code:

import asyncio
import json
from secret_config import RPC_ENDPOINT
from websockets import connect

from time import sleep

async def get_event():
    print("Started loop")
    async with connect(RPC_ENDPOINT) as ws:
        await ws.send('{"id": 1, "method": "eth_subscribe", "params": ["logs", {"topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}]}')
        subscription_response = await ws.recv()
        print(subscription_response)
        # you are now subscribed to the event 
        # you keep trying to listen to new events (similar idea to longPolling)
        while True:
            try:
                message = await asyncio.wait_for(ws.recv(), timeout=60)
                data = json.loads(message)
                result = data["params"]["result"]
                print(f"pairf"token address: {result['address']}, block: {int(result['blockNumber'], 16)}, tr_hash: {result['transactionHash']}")
                pass
            except:
                pass

if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    while True:
        loop.run_until_complete(get_event())

My question is: Is it 100% sure that the events will come in the right order of execution?

Or it is possible that sometimes, the events are not sent in the right order? I am planning to run this code on all EVM blockchains.

I am using eth_subscribe to log for all token transfer events that are happening on the blockchain.

Here is my code:

import asyncio
import json
from secret_config import RPC_ENDPOINT
from websockets import connect

from time import sleep

async def get_event():
    print("Started loop")
    async with connect(RPC_ENDPOINT) as ws:
        await ws.send('{"id": 1, "method": "eth_subscribe", "params": ["logs", {"topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}]}')
        subscription_response = await ws.recv()
        print(subscription_response)
        # you are now subscribed to the event 
        # you keep trying to listen to new events (similar idea to longPolling)
        while True:
            try:
                message = await asyncio.wait_for(ws.recv(), timeout=60)
                data = json.loads(message)
                result = data["params"]["result"]
                print(f"pair address: {result['address']}, block: {int(result['blockNumber'], 16)}, tr_hash: {result['transactionHash']}")
                pass
            except:
                pass

if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    while True:
        loop.run_until_complete(get_event())

My question is: Is it 100% sure that the events will come in the right order of execution?

Or it is possible that sometimes, the events are not sent in the right order? I am planning to run this code on all EVM blockchains.

I am using eth_subscribe to log for all token transfer events that are happening on the blockchain.

Here is my code:

import asyncio
import json
from secret_config import RPC_ENDPOINT
from websockets import connect

from time import sleep

async def get_event():
    print("Started loop")
    async with connect(RPC_ENDPOINT) as ws:
        await ws.send('{"id": 1, "method": "eth_subscribe", "params": ["logs", {"topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}]}')
        subscription_response = await ws.recv()
        print(subscription_response)
        # you are now subscribed to the event 
        # you keep trying to listen to new events (similar idea to longPolling)
        while True:
            try:
                message = await asyncio.wait_for(ws.recv(), timeout=60)
                data = json.loads(message)
                result = data["params"]["result"]
                print(f"token address: {result['address']}, block: {int(result['blockNumber'], 16)}, tr_hash: {result['transactionHash']}")
                pass
            except:
                pass

if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    while True:
        loop.run_until_complete(get_event())

My question is: Is it 100% sure that the events will come in the right order of execution?

Or it is possible that sometimes, the events are not sent in the right order? I am planning to run this code on all EVM blockchains.

Source Link

Is eth_subscribe always sending logs in the right order

I am using eth_subscribe to log for all token transfer events that are happening on the blockchain.

Here is my code:

import asyncio
import json
from secret_config import RPC_ENDPOINT
from websockets import connect

from time import sleep

async def get_event():
    print("Started loop")
    async with connect(RPC_ENDPOINT) as ws:
        await ws.send('{"id": 1, "method": "eth_subscribe", "params": ["logs", {"topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}]}')
        subscription_response = await ws.recv()
        print(subscription_response)
        # you are now subscribed to the event 
        # you keep trying to listen to new events (similar idea to longPolling)
        while True:
            try:
                message = await asyncio.wait_for(ws.recv(), timeout=60)
                data = json.loads(message)
                result = data["params"]["result"]
                print(f"pair address: {result['address']}, block: {int(result['blockNumber'], 16)}, tr_hash: {result['transactionHash']}")
                pass
            except:
                pass

if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    while True:
        loop.run_until_complete(get_event())

My question is: Is it 100% sure that the events will come in the right order of execution?

Or it is possible that sometimes, the events are not sent in the right order? I am planning to run this code on all EVM blockchains.