-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay9_Airdrop.sol
33 lines (27 loc) · 1.11 KB
/
Day9_Airdrop.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract Airdrop is Ownable {
ERC20 private token;
mapping(address => bool) private claim;
uint amount = 100000000000000000000;
constructor(address _tokenAddr) {
token = ERC20(_tokenAddr);
}
//function where every user can claim tokens
function getAirdrop() public {
require(token.balanceOf(address(this)) >= amount, "Balance not enough.");
require(claim[msg.sender] == false, "Already claimed.");
token.transfer(msg.sender, amount); //18 decimals token
claim[msg.sender] = true;
}
//function to give airdrop to a set of addresses
function payAirdrop(address[] memory _recipients, uint _amount) onlyOwner public {
uint tot_amount = token.balanceOf(address(this));
require(tot_amount > _amount*_recipients.length, "Not enough balance");
for (uint256 i = 0; i < _recipients.length; ++i) {
token.transfer(msg.sender, _amount);
}
}
}