Skip to content

Instantly share code, notes, and snippets.

@xrzhuang
Created April 1, 2020 16:46
Show Gist options
  • Select an option

  • Save xrzhuang/7ca712726ad1ff56298c8f833b88854a to your computer and use it in GitHub Desktop.

Select an option

Save xrzhuang/7ca712726ad1ff56298c8f833b88854a to your computer and use it in GitHub Desktop.

Revisions

  1. xrzhuang created this gist Apr 1, 2020.
    30 changes: 30 additions & 0 deletions eco_btn.sol
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    pragma solidity ^0.4.18;

    contract EcoBtn {
    address private latestAddress;
    uint256 private latestBlock = 0;
    uint private amount = 0;

    uint public FIXED_AMOUNT_WEI = 1000000000000000000;

    constructor() public {
    latestBlock = block.number;
    latestAddress = msg.sender;
    }

    function claimTreasure() public{
    require(block.number - latestBlock >= 3);
    require(msg.sender == latestAddress);

    msg.sender.transfer(address(this).balance);
    amount = 0;
    }

    function pressBtn() public payable{
    require(msg.value >= FIXED_AMOUNT_WEI);

    msg.sender.transfer(msg.value-FIXED_AMOUNT_WEI);
    amount++;
    latestBlock = block.number;
    }
    }