2

I am trying to subscribe to Ethereum events (via Infura) but I'm a bit confused.

I am following this documentation: https://web3js.readthedocs.io/en/v1.2.0/web3-eth-subscribe.html#subscribe-logs

Here is my code:

const ep = 'wss://goerli.infura.io/ws/v3/<XXX>'
const Web3 = require('web3')
const address = '0xdf9E19BB25A200429511bE09892A9B6A4842d483'
const web3ws = new Web3(
  new Web3.providers.WebsocketProvider( ep )
)

web3ws.eth.subscribe( 'logs', {
  address: address,
}, function( error, result ) {
  if ( error ) {
    console.log("Subscription error: "+error)
  } else {
    console.log("Subscription result: %o",result)
  }
})

This seems to work, as I am getting logs (see below), however I don't understand it.

I assume log_id is unique entry, you can see log_7cc1f0b8 is added (removed: false), then later we see it again (removed: true). What does it mean removed? I thought blockchain was immutable? This id never come again, so it was removed forever? I don't get it.

Subscription result: {
  address: '0xdf9E19BB25A200429511bE09892A9B6A4842d483',
  topics: [
    '0x49fe0aa457994ea66f7777afb52c37e4e53ec3e74288aad4c0c45455e035ba88',
    '0xa0fb64729bbcc96db98b0fb392dba8df5abef85b4b257b702317fcc8eb8d249a',
    [length]: 2
  ],
  data: '0x000000000000000000000000000000000000000000000000000000005dde8e86',
  blockNumber: 1723000,
  transactionHash: '0xf96966ee7f407be553438afce506fdf2c8e85e27d9df6301db001259d3250775',
  transactionIndex: 0,
  blockHash: '0xc57affdb6705078567eb0a0a28985af18571b53210fff3e037c62a34495463e3',
  logIndex: 0,
  removed: false,
  id: 'log_7cc1f0b8'
}
Subscription result: {
  address: '0xdf9E19BB25A200429511bE09892A9B6A4842d483',
  topics: [
    '0x49fe0aa457994ea66f7777afb52c37e4e53ec3e74288aad4c0c45455e035ba88',
    '0xa0fb64729bbcc96db98b0fb392dba8df5abef85b4b257b702317fcc8eb8d249a',
    [length]: 2
  ],
  data: '0x000000000000000000000000000000000000000000000000000000005dde8e86',
  blockNumber: 1723000,
  transactionHash: '0xf96966ee7f407be553438afce506fdf2c8e85e27d9df6301db001259d3250775',
  transactionIndex: 1,
  blockHash: '0x1298bdb912230311e91d3bf061e7f81310ee37fc0bba6e33716d5cf65a0bcc63',
  logIndex: 1,
  removed: false,
  id: 'log_46cc14bd'
}
Subscription result: {
  address: '0xdf9E19BB25A200429511bE09892A9B6A4842d483',
  topics: [
    '0x49fe0aa457994ea66f7777afb52c37e4e53ec3e74288aad4c0c45455e035ba88',
    '0xa0fb64729bbcc96db98b0fb392dba8df5abef85b4b257b702317fcc8eb8d249a',
    [length]: 2
  ],
  data: '0x000000000000000000000000000000000000000000000000000000005dde8e86',
  blockNumber: 1723000,
  transactionHash: '0xf96966ee7f407be553438afce506fdf2c8e85e27d9df6301db001259d3250775',
  transactionIndex: 0,
  blockHash: '0xc57affdb6705078567eb0a0a28985af18571b53210fff3e037c62a34495463e3',
  logIndex: 0,
  removed: true,
  id: 'log_7cc1f0b8'
}
guesty
  • 21
  • 2
  • check this https://ethereum.stackexchange.com/questions/17380/how-reliable-are-ethereum-logs . And https://ethereum.stackexchange.com/questions/37437/log-index-change-during-chain-reorganization – Majd TL Nov 27 '19 at 15:27
  • thanks, but I do not think this can be due to a reorg, as the block number is the same for all 3 entries. – guesty Nov 27 '19 at 16:53
  • It is a reorg, the block hashes and transaction index are different. – Ismael Nov 27 '19 at 17:31
  • ah, ok, i think i get it. The middle entry is the replacement for the first entry (which got backed out as stated by the third entry) – guesty Nov 27 '19 at 18:00

0 Answers0