Skip to content

Instantly share code, notes, and snippets.

@andy8052
Created April 18, 2019 20:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save andy8052/8499f81b530b77d563fe2fc272cec758 to your computer and use it in GitHub Desktop.
pragma solidity >=0.5.0;
contract ERC20 {
function totalSupply() public view returns (uint);
function balanceOf(address tokenOwner) public view returns (uint balance);
function allowance(address tokenOwner, address spender) public view returns (uint remaining);
function transfer(address to, uint tokens) public returns (bool success);
function approve(address spender, uint tokens) public returns (bool success);
function transferFrom(address from, address to, uint tokens) public returns (bool success);
event Transfer(address indexed from, address indexed to, uint tokens);
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
}
contract BatchERCSender {
//Send tokens from another address after you have approved this contract for sending
function sendApproved(address token, address[] memory to, uint amount) public {
ERC20 erc20 = ERC20(token);
require(erc20.allowance(msg.sender, address(this)) >= amount * to.length, "Token allowence is not high enough");
for (uint x = 0; x < to.length; x++) {
erc20.transferFrom(msg.sender, to[x], amount);
}
}
//Send tokens directly from the contract
// IMPORTANT: if you actually want to use this you should add authorization
function send(address token, address[] memory to, uint amount) public {
ERC20 erc20 = ERC20(token);
require(erc20.balanceOf(address(this)) >= amount * to.length, "Token allowence is not high enough");
for (uint x = 0; x < to.length; x++) {
erc20.transfer(to[x], amount);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment