A lottery number you can pay by address: send ether here and it buys tickets for your chosen number on your behalf, refunding anything left over.
Historical Significance
This is a user interface built out of addresses. Picking a lottery number normally means constructing a transaction with the right calldata; here the operator deploys one contract per number and a player only has to send ether to the right address, which any wallet can do. The cost is a contract deployment per number, paid once, and the benefit is that playing needs no ABI, no dapp and no wallet that understands contract calls.
Key Facts
Description
Two values are fixed at construction: a number, exposed publicly as dream, and the lottery contract. The whole contract is a payable fallback.
Send it ether and it calls buyTicketsFor on the lottery, naming the sender as the buyer and the stored number as the pick. Whatever the lottery does not spend stays behind, so the fallback finishes by sending any remaining balance back to the sender. A call from the lottery itself returns immediately and does nothing, which is what stops the refund from re-entering the purchase.
There is no owner, no way to change the number, and no way to point it at a different lottery. Each deployment is one number, permanently.
Source Verified
Byzantium Era
First Metropolis hard fork. Added zk-SNARK precompiles, REVERT opcode, and staticcall.
Bytecode Overview
Verified Source Available
This contract has verified source code.
View Verification ProofShow source code (Solidity)
// Submitted by EthereumHistory (ethereumhistory.com)
pragma solidity ^0.4.15;
contract Lottery {
function buyTicketsFor(address _for, uint256 _dream) public payable;
}
contract Ticket {
uint256 public dream;
address lottery;
function () public payable {
if (msg.sender == lottery) {
return;
}
Lottery(lottery).buyTicketsFor.value(msg.value)(msg.sender, dream);
if (address(this).balance != 0) {
msg.sender.transfer(address(this).balance);
}
}
}