Created
October 3, 2023 14:10
-
-
Save Violet-Bora-Lee/b19d67833ae102f79e99cca3b7c55bbb to your computer and use it in GitHub Desktop.
솔리디티 이벤트 예시
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.8.0; | |
contract SimpleToken { | |
mapping(address => uint256) public balances; | |
// 토큰 전송 이벤트 정의 | |
event Transfer(address indexed _from, address indexed _to, uint256 _amount); | |
constructor(uint256 initialSupply) { | |
balances[msg.sender] = initialSupply; | |
} | |
function transfer(address _to, uint256 _amount) public { | |
require(balances[msg.sender] >= _amount, "Insufficient balance"); | |
balances[msg.sender] -= _amount; | |
balances[_to] += _amount; | |
// 토큰 전송 시 이벤트 발생 | |
emit Transfer(msg.sender, _to, _amount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment