Last active
August 21, 2018 09:24
-
-
Save YoshihitoAso/91df0efc57f484eb77deca1d1b3c36c5 to your computer and use it in GitHub Desktop.
Solidity Sample 2
This file contains 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.4.24; | |
contract SimpleToken { | |
// (1) 状態変数の宣言 | |
string public name; // トークンの名前 | |
string public symbol; // トークンの単位 | |
uint256 public totalSupply; // トークンの総量 | |
mapping (address => uint256) public balanceOf; // 各アドレスの残高 | |
// (2) イベント通知 | |
event Transfer(address indexed from, address indexed to, uint256 value); | |
// (3) コンストラクタ | |
constructor(uint256 _supply, string _name, string _symbol) public { | |
balanceOf[msg.sender] = _supply; | |
name = _name; | |
symbol = _symbol; | |
totalSupply = _supply; | |
} | |
// (4) 送金 | |
function transfer(address _to, uint256 _value) public { | |
// (5) 不正送金チェック | |
require(balanceOf[msg.sender] >= _value); | |
require(balanceOf[_to] + _value > balanceOf[_to]); | |
// (6) 送信アドレスと受信アドレスの残高を更新 | |
balanceOf[msg.sender] -= _value; | |
balanceOf[_to] += _value; | |
// (7) イベント通知 | |
emit Transfer(msg.sender, _to, _value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment