Pay to get in

Now let’s make some coin!

Below you find a mapper contract to collect more than 0.49 ether in order to register the sender for a service. You can adjust the amount in function mapper(), of course. Once the minimum amount has been sent to the contract, the sender is registered for the service:

  • Contract accepts Ether using function() payable
  • The sender is registered by create_Member(address new_address)
  • You can send more than 0.5 ether (less is rejected and send back), but only one payment is accepted for each sender address.
  • The contract is owned
  • Only owner can get the money out with send_Ether_To_Owner()

This is very simple and Ethereum tokens offer more possibilities.

Our contract is here: 0x4f51b5bc96dc85226bd1e9510394f83a2d74bbb0

The registration will be a gateway to enter the messaging service on a private chain. You can either wait for the next blog post or send some coin already 😉

unknown

Mapper (Solidity contract)


pragma solidity ^0.4.4;
contract owned {
function owned() { owner = msg.sender; }
address owner;
modifier onlyOwner {
if (msg.sender != owner)
throw;
_;
}
function kill() {
if (msg.sender == owner) suicide(owner);
}
}


contract mapper is owned {
uint32 counter;
uint256 private value;
uint256 private price;
mapping (address => address) members;
event CreateMember(address new_address);
function mapper() {
counter = 0;
value= 0;
price= 490000000000000000;
}
function() payable {
if ( msg.value > price && check_Address(msg.sender) == false ) {
create_Member(msg.sender);
value+= msg.value;
} else throw;
}
function create_Member(address new_address) private returns (bool) {
members[msg.sender]= new_address;
counter++;
CreateMember(new_address);
return true;
}
function send_Ether_To_Owner() onlyOwner returns (bool) {
value= 0;
return owner.send(this.balance);
}
function get_Counter() constant returns (uint32) {
return counter;
}
function get_Value() constant returns (uint256) {
return value;
}
function check_Address (address a) constant returns (bool) {
if (members[a] == a) return true; else return false;
}
}

One thought to “Pay to get in”

Mentions

  • Ethereum application recipe – Blockchain Log

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.