Skip to content

Instantly share code, notes, and snippets.

@shigahi
Last active July 15, 2018 00:43
Show Gist options
  • Save shigahi/1173350f7056aa730d5972439c7b436d to your computer and use it in GitHub Desktop.
Save shigahi/1173350f7056aa730d5972439c7b436d to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.13; //solidityのバージョン指定
contract Methoco {
address owner; //contractのイニシエータであるowner(Hashアドレスにて同定)を宣言
uint public akushuken; // 公開される握手券を宣言
uint constant price = 1 ether; //ブロックチェーンでやり取りされる単位(価格)を1 etherと定義
mapping (address => uint) public fans; //握手券を購入するファン(アドレス)をマッピング
function Methoco(){
owner = msg.sender; //オーナーのアドレス(msg.sender)を指定
akushuken = 100; //握手券の総数を指定
}
function buyAkushuken(uint amount) payable { //握手券購入関数。payableはetherをやり取りする際に使う指定語
if (msg.value != price){
revert(); //支払う価格が1eth以外の場合を弾く
}
fans[msg.sender] += amount;
akushuken -= amount;
if (akushuken == 0){
selfdestruct(owner); //握手券が完売したらownerにethを戻してコントラクトを破壊する
}
}
function () payable{
buyAkushuken(1); //contractにつき一つ無記名のフォールバック関数が使用できる。この場合、単に1ethを送信すると握手券を1購入できるという関数。
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment