Skip to content

Instantly share code, notes, and snippets.

@akaz00
Forked from doey-default/MyToken.sol
Created January 24, 2019 07:52
Show Gist options
  • Select an option

  • Save akaz00/917fe316e108e582f34886ee51f5fdf7 to your computer and use it in GitHub Desktop.

Select an option

Save akaz00/917fe316e108e582f34886ee51f5fdf7 to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.24;
import "./ERC20Interface.sol";
import "./SafeMath.sol";
contract MyToken is ERC20Interface { // 계약 선언
using SafeMath for uint;
string public constant name = "MyToken"; // 토큰명
string public constant symbol = "MTK"; // 토큰 기호
uint8 public constant decimals = 18; // 소수점 수
uint private _tokenSupply; // 총 발행 수
address private _owner; // 소유자
mapping(address => uint) private _balances; // 사용자당 잔액
mapping(address => mapping(address => uint)) private _allowed;
uint private _totalProvided;
function MyToken() public
{
_tokenSupply = 15000000000; // 총 발행양 할당
_owner = msg.sender; // 토큰 소유자
_balances[_owner] = _tokenSupply; // 소유자에게 토큰 할당
_totalProvided = 0;
}
function totalSupply() public constant returns (uint) // 총 토큰량 조회
{
return _tokenSupply;
}
function balanceOf(address tokenOwner) public constant returns (uint balance) // tokenOwner 의 잔액 조회
{
return _balances[tokenOwner];
}
// tokenOwner 계좌에서 spender 에게 부여된 권한량 조회
function allowance(address tokenOwner, address spender) public constant returns (uint remaining)
{
return _allowed[tokenOwner][spender];
}
// to 에게 tokens 만큼 송금
function transfer(address to, uint tokens) public returns (bool success)
{
if (tokens > 0 && balanceOf(msg.sender) >= tokens) {
_balances[msg.sender] = _balances[msg.sender].sub(tokens); // 보내는 사람 계좌에서 잔액 감소
_balances[to] = _balances[to].add(tokens); // 받는 사람 계좌에서 잔액 증가
Transfer(msg.sender, to, tokens); // 송금 내역 저장 (이더스캔에서 조회)
return true;
}
return false;
}
// msg.sender가 spender에게 tokens 만큼 송금 권한 부여
function approve(address spender, uint tokens) public returns (bool success)
{
if (tokens > 0 && balanceOf(msg.sender) >= tokens) {
_allowed[msg.sender][spender] = tokens; // 계좌주와 spender 등록
Approval(msg.sender, spender, tokens); // 권한 위임 내역 저장
return true;
}
return false;
}
// from의 계좌에서 to 에게 tokens 만큼 송금 (spender 호출)
function transferFrom(address from, address to, uint tokens) public returns (bool success)
{
if (tokens > 0 && balanceOf(from) >= tokens && _allowed[from][msg.sender] >= tokens) { // 출금 허용액 보다 작은 경우
_balances[from] = _balances[from].sub(tokens); // 출금 진행
_allowed[from][msg.sender] = _allowed[from][msg.sender].sub(tokens); // 허용액 조정
_balances[to] = _balances[to].add(tokens); // 입금 진행
Transfer(msg.sender, to, tokens);
return true;
}
return false;
}
function burn(uint tokens) private returns (bool success) {
if( tokens > 0 && balanceOf(_owner) >= tokens ) {
_balances[_owner] -= tokens;
_tokenSupply -= tokens;
return true;
}
return false;
}
function buyToken() payable public returns (bool success) {
if(msg.value >= 0 && block.timestamp < 1524000000 && msg.value + _totalProvided <= 100000000){ // 구매 조건
uint tokens = msg.value * 10000; // 토큰 비율
_balances[_owner] -= tokens;
_balances[msg.sender] += tokens;
Transfer(_owner, msg.sender, tokens);
_totalProvided += msg.value; // 구매 제한량 확인
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment