1

Just a small question regarding how solidity event works. Let's say I have a function buyCandy(). At the end of the function I attached event:

emit LogBuyCandy(msg.sender);

event LogBuyCandy(address _buyer);

Let's say there are 10 people who's in the site at the same time, viewing the list of candies to buy. When one of the users bought the candy which triggered the event, I'm popping up a message that reads something like "0x...(address) bought the candy".

ex:

listenToEvents: function() {
    App.contracts.Candy.deployed().then(function(instance) {
        instance.LogBuyCandy({},{}).watch(function(error, event) {
            if (!error) {
                // popup message

My question is, can everyone see that message at the same time? or is it just the one who bought the candy seeing the message only?

0

You can do this with web3 events as shown in web3 documentation

For example:

YourWeb3WsInstance.events.LogBuyCandy({})
.on('data', (event) => {
    console.log(event)
}
  • Thanks for your answer. I've tested with existing codes and it turned out that people could see the message at the same time. – bbusdriver Jun 26 '18 at 18:32

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.