Skip to content

Instantly share code, notes, and snippets.

@Zeegaths
Created January 29, 2024 00:52
Show Gist options
  • Save Zeegaths/bf8e236a5ddc6f88ee0efdf8b4dc6bed to your computer and use it in GitHub Desktop.
Save Zeegaths/bf8e236a5ddc6f88ee0efdf8b4dc6bed to your computer and use it in GitHub Desktop.
A smart contract that uses global functions in the message context
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
// Write a smart contract that defines and triggers 3-4 events
// Index the events so that they can be easily searched
// Capture these events in your JavaScript code
contract Events {
uint public x = 0;
event AddressLog(address indexed sender, string message);
event DepositAmount(address indexed _from, uint _value, string message);
event ValueIncrease(address indexed owner, uint oldValue, uint newValue, string message);
function checkEvents() public payable {
emit AddressLog(msg.sender, "Log message emitted");
emit DepositAmount(msg.sender, msg.value, "Deposit successful");
}
function addAmount() public {
uint oldValue = x;
x++;
emit ValueIncrease(msg.sender, oldValue, x, "Value increased");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment