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'
}
4

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.