-
Notifications
You must be signed in to change notification settings - Fork 2
/
033-more-on-events.sol
33 lines (28 loc) · 1002 Bytes
/
033-more-on-events.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
/**
* @title More on Events in Solidity
* @notice Events have lower gas cost that storage
*/
contract LearnMoreOnEvents {
// To create an event we consider two things
// 1. Declare th event and
// 2. emit that event
// example event declaration to funds transfer
// use the CamelCase convention for naming your events
// only use 3 indexed per events - which enables the outside
// consumer to filter what they need
event NewTrade(
uint256 indexed data,
address indexed from,
address to,
uint256 indexed amount
);
// function to perform a trade
function trade(address to, uint256 amount) external {
// an outside consumer can see the event throught web3js
// block.timestamp is a global varianle that gives us the current timestamp
// emitting the event
emit NewTrade(block.timestamp, msg.sender, to, amount);
}
}