Skip to content

Instantly share code, notes, and snippets.

@Anish-Agnihotri
Created March 6, 2021 22:53
Show Gist options
  • Save Anish-Agnihotri/5b38e3816966ba2761e0a8a27db72f27 to your computer and use it in GitHub Desktop.
Save Anish-Agnihotri/5b38e3816966ba2761e0a8a27db72f27 to your computer and use it in GitHub Desktop.
Quick contract implementing Matteo's idea
// SPDX-License-Identifier: MIT
pragma solidity <=0.7.4;
// @name Rich
// @dev Contract to track richest owner and name and take ownership by paying cost
contract Rich {
string public richest = ""; // Name of richest
uint public cost = 0.001 ether; // Cost to take ownership
address payable public currentOwner; // Current richest owner
// Event to emit on owner change
event NewRichest(address indexed to, uint cost);
// On deployment
constructor() {
// Set initial richest to Anish
richest = "Anish Agnihotri";
currentOwner = msg.sender;
}
// @dev take ownership and become the richest
// @param _name to set as richest
function takeOwnership(string calldata _name) external payable {
require(msg.value == cost, "Rich: Insufficient paid value"); // Require payment
require(msg.sender != currentOwner, "Rich: Cannot be current owner"); // Ensure no duplicacy
currentOwner.transfer(msg.value); // Transfer fees to old owner
richest = _name; // Update name of richest
currentOwner = msg.sender; // Change current owner
cost = cost * 3 / 2; // Multiply cost of ownership by 1.5
// Emit new owner event
emit NewRichest(msg.sender, cost);
}
}
@davidroman0O
Copy link

Smart way to get some ETH 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment