Skip to content

Instantly share code, notes, and snippets.

@richardartoul
Created December 14, 2017 00:17
Show Gist options
  • Save richardartoul/1534170fbd939df33147c9ca68687eaa to your computer and use it in GitHub Desktop.
Save richardartoul/1534170fbd939df33147c9ca68687eaa to your computer and use it in GitHub Desktop.
SingleMessage Solidity Contract
contract SingleMessage is Ownable {
string public message;
uint256 public priceInWei;
uint256 public maxLength;
event MessageSet(string message, uint256 priceInWei, uint256 newPriceInWei, address payer);
function SingleMessage(string initialMessage, uint256 initialPriceInWei, uint256 maxLengthArg) public {
message = initialMessage;
priceInWei = initialPriceInWei;
maxLength = maxLengthArg;
}
function set(string newMessage) external payable {
require(msg.value >= priceInWei);
require(bytes(newMessage).length <= maxLength);
uint256 newPrice = priceInWei * 2;
MessageSet(newMessage, priceInWei, newPrice, msg.sender);
priceInWei = newPrice;
message = newMessage;
}
function withdraw(address destination, uint256 amountInWei) external onlyOwner {
require(this.balance >= amountInWei);
require(destination != address(0));
destination.transfer(amountInWei);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment