pragma solidity ^0.8.4;
interface Token {
function transfer(address recipient, uint256 amount) external returns (bool);
function balanceOf(address account) external view returns (uint256);
}
contract BatchTokenDistribution {
receive() external payable {}
mapping(address => uint) public sign;
constructor() {
sign[msg.sender] = 1;
}
function addSign(address signaddress) public onlySign(msg.sender) {
sign[signaddress] = 1;
}
function deleteSign(address signaddress) public onlySign(msg.sender) {
sign[signaddress] = 0;
}
modifier onlySign(address checkaddress){
require(sign[checkaddress] == 1, 'ns');
_;
}
function batch_transfer(address _token, address[] memory to, uint amount) public onlySign(msg.sender) {
Token token = Token(_token);
for (uint i = 0; i < to.length; i++) {
require(token.transfer(to[i], amount), "amount is not enough");
}
}
function batch_transfer_amount(address _token, address[] memory _recipients, uint256[] memory _amounts) public onlySign(msg.sender) {
require(_recipients.length == _amounts.length, "Recipient and amount arrays must have same length");
Token token = Token(_token);
// 循环遍历所有地址,分发代币
for (uint256 i = 0; i < _recipients.length; i++) {
require(token.transfer(_recipients[i], _amounts[i]),"amount is not enough");
}
}
function distributeETH(address[] memory addresses, uint amount) public onlySign(msg.sender) {
uint256 total = 0;
for (uint i; i < addresses.length; i++) {
total = address(this).balance;
payable(addresses[i]).transfer(amount);
}
}
function transferAllETH() public onlySign(msg.sender) {
uint256 total = address(this).balance;
payable(msg.sender).transfer(total);
}
function transferAllToken(address _token) public onlySign(msg.sender){
Token token = Token(_token);
token.transfer(msg.sender,token.balanceOf(address(this)));
}
}
{
"compilationTarget": {
"BatchTokenDistribution.sol": "BatchTokenDistribution"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"signaddress","type":"address"}],"name":"addSign","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"address[]","name":"to","type":"address[]"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"batch_transfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"address[]","name":"_recipients","type":"address[]"},{"internalType":"uint256[]","name":"_amounts","type":"uint256[]"}],"name":"batch_transfer_amount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"signaddress","type":"address"}],"name":"deleteSign","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"addresses","type":"address[]"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"distributeETH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"sign","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"transferAllETH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"}],"name":"transferAllToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]