Skip to content

Commit

Permalink
correction and elaboration on clearSubscriptions at migration guide
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad-Altabba committed May 30, 2023
1 parent 8c5ea34 commit fd3d182
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions docs/docs/guides/web3_migration_guide/subscribe_migration_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,18 @@ web3.eth.clearSubscriptions(function (error, success) {

// in 4.x
const subscription = await web3.eth.subscribe('newHeads');
subscription.unsubscribe().then(
console.log(), // [...] Array of subsription ids

// note that in version 4.x the way you get notified for `data` and `error` has changed
newBlocksSubscription.on('data', async blockhead => {
console.log('New block header: ', blockhead);
});
newBlocksSubscription.on('error', error =>
console.log('Error when subscribing to New block header: ', error),
);

const ids = await web3.eth.clearSubscriptions(function (error, success);
console.log(ids); // [...] An array of subscription ids that were cleared

// note that you can unsubscribe from a specific subscription by calling unsubscribe()
// on that subscription object: `await subscription.unsubscribe();` and this would return void if succeeded.
```

0 comments on commit fd3d182

Please sign in to comment.