Skip to content

Instantly share code, notes, and snippets.

@YoshihitoAso
Last active August 21, 2018 09:24
Show Gist options
  • Save YoshihitoAso/91df0efc57f484eb77deca1d1b3c36c5 to your computer and use it in GitHub Desktop.
Save YoshihitoAso/91df0efc57f484eb77deca1d1b3c36c5 to your computer and use it in GitHub Desktop.
Solidity Sample 2
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