0

I am trying to setup a node to be able to query all BEP20 transactions in real time.

My eth.syncing stats are:

> eth.syncing
{
  currentBlock: 9489998,
  highestBlock: 9490087,
  knownStates: 195328608,
  pulledStates: 195258505,
  startingBlock: 9487094
}

This is what I'm using

{"jsonrpc":"2.0", "id": 2, "method": "eth_subscribe", "params": ["logs", {"topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}]}

But I only get the following answer, and nothing more:

{"jsonrpc":"2.0","id":2,"result":"0x6760537a1d6add4f87899036f1826770"}

Anything I could be missing out?

blasrodri
  • 101
  • 1

1 Answers1

1

What you did was ask for a subscription, that won't give you anything other than an id to use to unsubscribe when you finish your work.

after subscribing, the node you are using will start sending you messages. if you are not constantly listening for them they simply won't show up. for this you will need to use a websocket provider.

if you are using python here how to do it :

import asyncio
import json

from web3 import Web3 from web3.middleware import geth_poa_middleware import requests from websockets import connect from eth_abi import decode_single, decode_abi

adapter = requests.sessions.HTTPAdapter(pool_connections=50000, pool_maxsize=50000) session = requests.Session() w3 = Web3(Web3.WebsocketProvider("<YOUR-WS-PROVIDER>")) w3.middleware_onion.inject(geth_poa_middleware, layer=0) // this only for PoA chains like BSC

async def get_event(): async with connect("ws://localhost:8545") as ws: await ws.send({"jsonrpc":"2.0", "id": 2, "method": "eth_subscribe", "params": ["logs", {"topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}]} ) subscription_response = await ws.recv() print(subscription_response) while True: try: message = await asyncio.wait_for(ws.recv(), timeout=60) print(json.loads(message)) pass except: pass if name == "main": loop = asyncio.get_event_loop() while True: loop.run_until_complete(get_event())

Kaki Master Of Time
  • 3,060
  • 4
  • 19
  • 44