I am trying to implement a presale contract, I saw the above link. I am confused by this line -

 event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount);

I cannot find TokenPurchase coded anywhere except here -

   TokenPurchase(msg.sender, beneficiary, weiAmount, tokens);

I cannot find where TokenPurchase is implemented. Has anyone any ideas?


1 Answer 1


Events aren't implemented. They just are.

That first line defines an event; specifically, what are the arguments and which ones are indexed.

The second line logs an event. That's it. That's all you need to log an event. Using web3js, it's possible to find whatever events have been logged by a given contract.

Under the hood, all events are essentially wrappings of the LOG opcodes. They all work identically, which is why there's no need to "implement" an event.

  • I was reaching that conclusion. But how does someone know the point of the event? If there is no code what does someone look at - the name? What is point of events? Why not just have a function? Aug 21, 2017 at 15:57
  • Events can be easily read from the outside world, whereas another function call would be impossible to know about from the outside world except via tracing the transaction. As for how someone knows what an event does, you just have to read the context. Think of it like a "print" statement in other languages. Aug 21, 2017 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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