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.


| improve this question | | | | |

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.

| improve this answer | | | | |
  • Thanks for figuring me out this :D I don't know that this feature only suppose on web3 1.0 :D – hqt May 21 '18 at 18:58
  • If you have time, please view my following question: ethereum.stackexchange.com/questions/49085/… thanks :D – hqt May 21 '18 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.