Subscribing solidity events over websocket provider

Hello All,

I am looking for subscribing the event on websocket most likely as given in below link
https://hanezu.github.io/posts/Enable-WebSocket-support-of-Ganache-CLI-and-Subscribe-to-Events.html
I m not sure whether its old way for subscribing the solidity event or something that truffle handling insides its own way.

Lets take a scenario of supply chain where a customer placed an order.As soon as same order has approved there is an event emitted in smart contract which should only notify to that customer only i.e. only to those listeners who subscribed to that event.Customer’s frond end just subscribed the event and when any notification available for that customer ethereum will push notification to him so frond end don’t need to poll it at regular time interval.

Please help me to understand with an code example if you have.
Thanks.

The tutorial you linked to uses web3.eth.subscribe() method which is a general way of listening to all kids of events on the Blockchain, not just smart contract event.

Check out this video tutorial when I explain a more simple way of listening to events with web3 contract objects.

Thanks @jklepatch. Please share If any example you have of web3 using websocket provider would be great help.

The tutorial I linked to before does use websocket provider. When you instantiate web3 you have to do it that way:

const web3 = new Web3(Web3.providers.WebSocketProvider('ws://localhost:8545'));
1 Like