I am using truffle-contract for connecting between frontend and smart contract. Currently, I can call method on smart contract. But now I want to subscribe to certain events on smart contract. How can I do this.
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.Sign up to join this community
Event subscription is a new feature available from web3 1.0 beta. And now, truffle-contract's upgrade to web3 1.0 is available as an experimental nightly build. So if you are not in production and feel adventurous, you can try poking around.
If you are in production, on the other hand, you may use web3 1.0 beta directly without truffle-contract's abstraction. However, since major providers like MetaMask don't support web3 1.0 subscription yet(web3.js v.1.0 deprecated HttpProvider in favor of WebSocketProvider), if you'd like to use it, you may need to setup your custom WebSocket provider for now.
If all these are not your viable options, you can still manually process the events provided in logs.