4

I would like to continuously get the transactions sended to a specific address while using a light client. I underscore that I am talking about regular transactions, not the contract invocations.

As far as I understood, there is no elegant way to do that in Ethereum. The only two options that I see is to get the whole block and parse the transactions in JS ( as was suggested through eth_getBlockByNumber Common useful JavaScript snippets for geth ). Or to first get the transaction hashes and request the transaction receipts for each of them through eth_getTransactionReceipt.

But what exactly will light client will do in the second case? Will it issue a separate TCP packet for EACH transaction receipt? Will the overhead in such a case be more than that of the first above described option? So, what do you think is the most viable option?

Also, it was suggested here ( https://ethereum.stackexchange.com/a/45957/49595 ) to use getBalance (i.e. eth_getBalance) first to make sure that the balance has changed (so that some transaction appeared within the block). Hm. Pretty cool, but still - what is the best way to to get the sender's address if no transaction hash is known beforehand?

Edit: At the same time I don't quite understand how eth_getBalance will work on the light client. According to the LES specification, it has to download the whole block even if only the balance from one certain transaction is required. Right?

Edit2: I am just testing out JSON RPC on my private blockchain. I made two transactions by transfer of 1 Wei from one account to another. Then I outputted the pending block header. The sad part is that logsBloom is all zeroes - so there is definitely no information is kept about regular transactions.

Edit3: I looked at LES specification once more. It has a GetReceipts function which accepts the hash of the block. And at the same time eth_getTransactionReceipt accepts the hash of the transaction instead. It is confusing, but it probably ultimately means that once any receipt is requested, the light client will call GetReceipts for the whole block. Which is a good idea in my case, since I have to pull all the receipts anyway.

0

Amberdata.io has an elegant way of doing what you are asking. If you would like to get every transaction sent to a specific address you may do so by using Amberdata's websockets.

const WebSocket = require('ws');
const ws = new WebSocket('wss://ws.web3api.io', {headers: {x-api-key:'<api_key>'}});

ws.on('open', () => {
  ws.send(JSON.stringify({
      jsonrpc: '2.0',
      method: 'subscribe',
      params: ['address:transactions', {address: '0x06012c8cf97bead5deae237070f9587f8e7a266d'}],
      id: 1,
    }));
});

ws.on('message', data => {
  console.log(JSON.stringify(JSON.parse(data), null, 2));
});

Now whenever the address receives/sends a transaction the websocket will receive a notification.

  • You probably misunderstood me. I am building true p2p app. What you proposing is a centralised solution. – reardenlife Apr 11 at 3:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.