‘emit’ keyword in Solidity

Although there are some more languages being developed, Solidity has been first choice of developers for smart contract development. Ethereum community is continuously working hard to ease & improve development with Solidity.

In a recent release (v0.4.21 at 8th March 2018), `emit` keyword has been introduced to emit the event. This will help to differentiate the functions from event which was one of the reason of TheDAO Hack which led to hard fork in Ethereum & gave birth to Ethereum Classic.

As per the solidity release notes :

General: Support and recommend using emit EventName(); to call events explicitly.
In order to make events stand out with regards to regular function calls, emit EventName() as opposed to just EventName() should now be used to "call" events.

You can know about the other implementations in this release here.

Now, new sample code to emit an event will look like :

pragma solidity ^0.4.21;
contract ClientReceipt {
event Deposit(
address indexed _from,
bytes32 indexed _id,
uint _value
function deposit(bytes32 _id) public payable {
// Events are emitted using `emit`, followed by
// the name of the event and the arguments
// (if any) in parentheses. Any such invocation
// (even deeply nested) can be detected from
// the JavaScript API by filtering for `Deposit`.
emit Deposit(msg.sender, _id, msg.value);

Make sure your compiler version is 0.4.21 or higher, for lower ones, it will throw a compilation error.

You can go through a discussion to introduce `emit` keyword here.

Thanks for reading.

Any Comments, More Welcome.