Last active
January 5, 2019 13:24
-
-
Save 0xAshish/84b0f5e44b846ae4e3b216b6890ab2b4 to your computer and use it in GitHub Desktop.
faucet for erc20 and ETH
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.24; | |
/** | |
* @title Ownable | |
* @dev The Ownable contract has an owner address, and provides basic authorization control | |
* functions, this simplifies the implementation of "user permissions". | |
*/ | |
contract Ownable { | |
address private _owner; | |
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); | |
/** | |
* @dev The Ownable constructor sets the original `owner` of the contract to the sender | |
* account. | |
*/ | |
constructor () internal { | |
_owner = msg.sender; | |
emit OwnershipTransferred(address(0), _owner); | |
} | |
/** | |
* @return the address of the owner. | |
*/ | |
function owner() public view returns (address) { | |
return _owner; | |
} | |
/** | |
* @dev Throws if called by any account other than the owner. | |
*/ | |
modifier onlyOwner() { | |
require(isOwner()); | |
_; | |
} | |
/** | |
* @return true if `msg.sender` is the owner of the contract. | |
*/ | |
function isOwner() public view returns (bool) { | |
return msg.sender == _owner; | |
} | |
/** | |
* @dev Allows the current owner to relinquish control of the contract. | |
* @notice Renouncing to ownership will leave the contract without an owner. | |
* It will not be possible to call the functions with the `onlyOwner` | |
* modifier anymore. | |
*/ | |
function renounceOwnership() public onlyOwner { | |
emit OwnershipTransferred(_owner, address(0)); | |
_owner = address(0); | |
} | |
/** | |
* @dev Allows the current owner to transfer control of the contract to a newOwner. | |
* @param newOwner The address to transfer ownership to. | |
*/ | |
function transferOwnership(address newOwner) public onlyOwner { | |
_transferOwnership(newOwner); | |
} | |
/** | |
* @dev Transfers control of the contract to a newOwner. | |
* @param newOwner The address to transfer ownership to. | |
*/ | |
function _transferOwnership(address newOwner) internal { | |
require(newOwner != address(0)); | |
emit OwnershipTransferred(_owner, newOwner); | |
_owner = newOwner; | |
} | |
} | |
/** | |
* @dev Faucet rate limit | |
*/ | |
contract Faucet is Ownable { | |
mapping(address => uint256) public lastFaucets; | |
uint256 private amount; | |
constructor () public | |
{ | |
amount = 3; | |
} | |
function updateAmount(uint256 _amount) public onlyOwner { | |
amount = _amount; | |
} | |
function() payable {} | |
/** | |
* faucet | |
*/ | |
function faucet( | |
address _to | |
) | |
public | |
payable | |
{ | |
require(block.number - lastFaucets[_to] > 10); | |
lastFaucets[_to] = block.number; | |
_to.transfer(amount); | |
} | |
} | |
interface IERC20 { | |
function totalSupply() external view returns (uint256); | |
function balanceOf(address who) external view returns (uint256); | |
function allowance(address owner, address spender) external view returns (uint256); | |
function transfer(address to, uint256 value) external returns (bool); | |
function approve(address spender, uint256 value) external returns (bool); | |
function transferFrom(address from, address to, uint256 value) external returns (bool); | |
event Transfer(address indexed from, address indexed to, uint256 value); | |
event Approval(address indexed owner, address indexed spender, uint256 value); | |
} | |
/** | |
* @dev Faucet rate limit | |
*/ | |
contract FaucetMaticToken is Ownable { | |
mapping(address => uint256) public lastFaucets; | |
uint256 private amount; | |
address public token; | |
constructor () public | |
{ | |
amount = 3; | |
} | |
function updateAmount(uint256 _amount) public onlyOwner { | |
amount = _amount; | |
} | |
function updateToken(address _token) public onlyOwner { | |
token = _token; | |
} | |
/** | |
* faucet | |
*/ | |
function faucet( | |
address _to | |
) | |
public | |
{ | |
require(block.number - lastFaucets[_to] > 10); | |
lastFaucets[_to] = block.number; | |
IERC20(token).transfer(_to, amount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment