Notice: Ropsten is 'revived' once more... back up and kicking :-)

Contract Overview
Balance: 0.005 Ether
Transactions: 2 txns
 Latest 2 txns

TxHash Age From To Value [TxFee]
0x1b3e81ba198d2eb37e4c11b49dd2c7e22d9eb7c433391cca58fc4b2e9bab3cfb192 days 12 hrs ago0x58cc449f6246701ec7b7908feaa99af1cefdb21c  IN   0x6546254aeb308e9acc83d4d5eb4eb7329e1579eb0.005 Ether0.000129605
0xac40c79e403e8239d3a4a363c3217650ffaa2a2018cdcd133c27dc4b7d7333ed192 days 12 hrs ago0x58cc449f6246701ec7b7908feaa99af1cefdb21c  IN    Contract Creation0 Ether0.000890414


[ Download CSV Export  ] 
 Internal Transactions as a result of Contract Execution
View All
ParentTxHash Block Age From To Value
Warning: The Compiled Contract might be susceptible to ExpExponentCleanup (medium/high-severity), EventStructWrongData (very low-severity), NestedArrayFunctionCallDecoder (medium-severity) SolidityCompiler Bugs.

Contract Source Code Verified (Exact Match)
Contract Name: Lottery
Compiler Text: v0.4.21+commit.dfe3193c
Optimization Enabled: No
Runs (Optimiser):  200



  Contract Source Code   Find Similiar Contracts

pragma solidity ^0.4.21;

/* This lottery compares the low byte of sender's address with that of the
 * mined block. All matching entries for that block split the jackpot.

 * This method avoids two common attacks: by rewarding all winning entries,
 * no miner is incentivized to reorder entries. And by using the block hash,
 * which cannot be known at time of mining, there is no way to guess the
 * winning address and create one to match.
 *
 * This comes, however, with extra complexity and thus gas cost for an entry,
 * and the most cost is borne by the first bidder in a new block.
 */
 
contract Lottery {
    // note: uint is alias for uint256
    // constants
    uint public lastLottery;  // self-destruct after this one
    // initialization
    uint public rakePercent;  // percentage to skim for owner
    uint public ticketPrice;  // amount of wei to buy a ticket
    // state variables
    uint public lotteriesCompleted;  // lotteries finished, 0-based
    uint public lastTicketTime;  // unix timestamp of last ticket purchase
    uint public jackpot;  // prize at this moment
    uint public currentBlock;  // block for which entries are being tallied
    address[] public entries;  // addresses of ticket purchasers for this block
    address public owner;  // address of lottery contract publisher
    // for debugging only, move these to checkIfWon for release
    bytes32 public lastBlockhash;  // previous block's hash

    // events
    event LogMessage(string message);

    // constructor
    /* turns out if you don't pass arguments to constructor, it doesn't
     * fail but the variables are uninitialized, which in the case of uint
     * means they are 0. this is fine for `rake` but the ticket needs to
     * cost something.
     * lastLottery is set to the "terminate" argument, it must be nonzero
     * to have any effect, otherwise the contract ends at the default value.
     */
    function Lottery(uint rake, uint price, uint terminate) public {
        emit LogMessage("registering new lottery");
        owner = msg.sender;
        rakePercent = rake;  // specified in percent
        ticketPrice = price > 0 ? price : .005 ether;  // specified in wei
        // contract is deleted after lastLottery complete
        lastLottery = terminate > 0 ? terminate : 1;
        emit LogMessage("lottery registered");
    }

    // default, for anyone who just wants to send us money
    function () public payable {
        emit LogMessage("you've got money!");
    }

    // let owner withdraw all non-lottery funds
    function withdraw() public {
        uint available;
        if (msg.sender == owner) {
            available = address(this).balance - jackpot;
            if (available > 0) owner.transfer(available);
        }
    }

    // allow checking length of array from outside
    function totalEntries() public view returns (uint) {
        return entries.length;
    }

    // check for winner and set state
    /* another, possibly better if the lottery becomes really popular, would
     * be to store ticket purchases and block numbers in one or more mappings,
     * and let each participant check if they won and withdraw winnings.
     */

    // helper function
    function compareFinalByte(address entry, bytes32 hash)
            public pure returns (bool) {
        return uint(entry) & 0xff == uint(hash[31]);
    }
    
    function checkIfWon() private {
        uint winners = 0;
        uint payout;
        bool sent;
        require(block.number >= currentBlock);
        if (block.number > currentBlock) {
            lastBlockhash = block.blockhash(currentBlock);
            /* two loops through the entries:
             * first to count winners for dividing the pot,
             * the second to pay each winner.

             * don't check for winners if the pot has fewer than 10 entries,
             * or if lastBlockhash is 0, which means we couldn't get the
             * hash because we're over 256 blocks after the last was mined.
             */
            if (lastBlockhash > 0 && entries.length >= 10) {
                for (uint index = 0; index < entries.length; index++) {
                    address entry = entries[index];
                    if (compareFinalByte(entry, lastBlockhash)) {
                        winners++;
                    }
                }
            }
            if (winners > 0) {
                payout = jackpot / winners;
                for (index = 0; index < entries.length; index++) {
                    entry = entries[index];
                    if (compareFinalByte(entry, lastBlockhash)) {
                        /* attempt to send payout to each winner. any failed
                         * payments remain in the pot for next lottery.
                         */
                        sent = entry.send(payout);
                        if (sent) jackpot -= payout;
                    }
                }
                delete(entries);  // empties the list
                lotteriesCompleted++;
            }
            currentBlock = block.number;
        }
    }
    
    // lets customer buy a ticket
    function ticket() public payable {
        // we gladly accept donations over or under ticket purchase price
        if (lotteriesCompleted == lastLottery) {
            emit LogMessage("destroying contract");
            /* last lottery was ended either with ticket purchase, in which
             * case there will be one entry in the list, or by some as-yet-
             * nonexistent method which would not make a ticket entry.
             * 
             * if the former, reward the buyer who closed out the last lottery.
             */
            require(entries.length < 2);
            if (entries.length == 1) {
                emit LogMessage("final payout to ender of last lottery");
                selfdestruct(entries[0]);
            } else {
                emit LogMessage("final payout to lottery owner");
                selfdestruct(owner);
            }
        }
        checkIfWon();
        if (msg.value >= ticketPrice) {
            jackpot += ticketPrice;
            entries.push(msg.sender);
            lastTicketTime = now;
        }
    }
}
/* vim: set tabstop=4 expandtab shiftwidth=4 softtabstop=4: */

    Contract ABI  
[{"constant":true,"inputs":[],"name":"lotteriesCompleted","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"ticketPrice","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"withdraw","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"jackpot","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"ticket","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[],"name":"totalEntries","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"lastLottery","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"entries","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"lastTicketTime","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"currentBlock","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"lastBlockhash","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"entry","type":"address"},{"name":"hash","type":"bytes32"}],"name":"compareFinalByte","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[],"name":"rakePercent","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"rake","type":"uint256"},{"name":"price","type":"uint256"},{"name":"terminate","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":false,"name":"message","type":"string"}],"name":"LogMessage","type":"event"}]

  Contract Creation Code Switch To Opcodes View
6060604052341561000f57600080fd5b604051606080610ca4833981016040528080519060200190919080519060200190919080519060200190919050507f96561394bac381230de4649200e8831afcab1f451881bbade9ef209f6dd304806040518080602001828103825260178152602001807f7265676973746572696e67206e6577206c6f747465727900000000000000000081525060200191505060405180910390a133600860006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508260018190555060008211610102576611c37937e08000610104565b815b6002819055506000811161011957600161011b565b805b6000819055507f96561394bac381230de4649200e8831afcab1f451881bbade9ef209f6dd304806040518080602001828103825260128152602001807f6c6f74746572792072656769737465726564000000000000000000000000000081525060200191505060405180910390a1505050610b098061019b6000396000f3006060604052600436106100d0576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063104fb5461461013a5780631209b1f6146101635780633ccfd60b1461018c5780636b31ee01146101a15780636cc25db7146101ca5780637fef036e146101d45780638da5cb5b146101fd578063af0b4b2714610252578063b30906d41461027b578063bd5317db146102de578063e12ed13c14610307578063e2bc115914610330578063f17b14ec14610361578063f599b082146103bf575b7f96561394bac381230de4649200e8831afcab1f451881bbade9ef209f6dd304806040518080602001828103825260118152602001807f796f7527766520676f74206d6f6e65792100000000000000000000000000000081525060200191505060405180910390a1005b341561014557600080fd5b61014d6103e8565b6040518082815260200191505060405180910390f35b341561016e57600080fd5b6101766103ee565b6040518082815260200191505060405180910390f35b341561019757600080fd5b61019f6103f4565b005b34156101ac57600080fd5b6101b46104da565b6040518082815260200191505060405180910390f35b6101d26104e0565b005b34156101df57600080fd5b6101e761078d565b6040518082815260200191505060405180910390f35b341561020857600080fd5b61021061079a565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b341561025d57600080fd5b6102656107c0565b6040518082815260200191505060405180910390f35b341561028657600080fd5b61029c60048080359060200190919050506107c6565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34156102e957600080fd5b6102f1610805565b6040518082815260200191505060405180910390f35b341561031257600080fd5b61031a61080b565b6040518082815260200191505060405180910390f35b341561033b57600080fd5b610343610811565b60405180826000191660001916815260200191505060405180910390f35b341561036c57600080fd5b6103a5600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803560001916906020019091905050610817565b604051808215151515815260200191505060405180910390f35b34156103ca57600080fd5b6103d2610891565b6040518082815260200191505060405180910390f35b60035481565b60025481565b6000600860009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614156104d7576005543073ffffffffffffffffffffffffffffffffffffffff163103905060008111156104d657600860009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f1935050505015156104d557600080fd5b5b5b50565b60055481565b60005460035414156106fb577f96561394bac381230de4649200e8831afcab1f451881bbade9ef209f6dd304806040518080602001828103825260138152602001807f64657374726f79696e6720636f6e74726163740000000000000000000000000081525060200191505060405180910390a1600260078054905010151561056857600080fd5b60016007805490501415610658577f96561394bac381230de4649200e8831afcab1f451881bbade9ef209f6dd304806040518080602001828103825260258152602001807f66696e616c207061796f757420746f20656e646572206f66206c617374206c6f81526020017f747465727900000000000000000000000000000000000000000000000000000081525060400191505060405180910390a16007600081548110151561061457fe5b906000526020600020900160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16ff5b7f96561394bac381230de4649200e8831afcab1f451881bbade9ef209f6dd3048060405180806020018281038252601d8152602001807f66696e616c207061796f757420746f206c6f7474657279206f776e657200000081525060200191505060405180910390a1600860009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16ff5b610703610897565b6002543410151561078b57600254600560008282540192505081905550600780548060010182816107349190610a6b565b9160005260206000209001600033909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050426004819055505b565b6000600780549050905090565b600860009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60005481565b6007818154811015156107d557fe5b90600052602060002090016000915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60045481565b60065481565b60095481565b600081601f60208110151561082857fe5b1a7f0100000000000000000000000000000000000000000000000000000000000000027f0100000000000000000000000000000000000000000000000000000000000000900460ff8473ffffffffffffffffffffffffffffffffffffffff161614905092915050565b60015481565b600080600080600080945060065443101515156108b357600080fd5b600654431115610a645760065440600981600019169055506000600102600954600019161180156108ea5750600a60078054905010155b1561096657600091505b6007805490508210156109655760078281548110151561091057fe5b906000526020600020900160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905061094a81600954610817565b156109585784806001019550505b81806001019250506108f4565b5b6000851115610a5c578460055481151561097c57fe5b049350600091505b600780549050821015610a3b576007828154811015156109a057fe5b906000526020600020900160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690506109da81600954610817565b15610a2e578073ffffffffffffffffffffffffffffffffffffffff166108fc859081150290604051600060405180830381858888f1935050505092508215610a2d57836005600082825403925050819055505b5b8180600101925050610984565b60076000610a499190610a97565b6003600081548092919060010191905055505b436006819055505b5050505050565b815481835581811511610a9257818360005260206000209182019101610a919190610ab8565b5b505050565b5080546000825590600052602060002090810190610ab59190610ab8565b50565b610ada91905b80821115610ad6576000816000905550600101610abe565b5090565b905600a165627a7a72305820b91494c269725a433b2a8ebbd9634f1ecf01b429703131ab1e10f22bb66ebae90029000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

    Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [1] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [2] : 0000000000000000000000000000000000000000000000000000000000000000


   Swarm Source:
bzzr://b91494c269725a433b2a8ebbd9634f1ecf01b429703131ab1e10f22bb66ebae9

 

View All
Block Age transaction Difficulty GasUsed Reward
View All
Block Age UncleNumber Difficulty GasUsed Reward