Skip to content

Instantly share code, notes, and snippets.

@Violet-Bora-Lee
Created October 3, 2023 14:10
Show Gist options
  • Save Violet-Bora-Lee/b19d67833ae102f79e99cca3b7c55bbb to your computer and use it in GitHub Desktop.
Save Violet-Bora-Lee/b19d67833ae102f79e99cca3b7c55bbb to your computer and use it in GitHub Desktop.
솔리디티 이벤트 예시
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