Created
April 18, 2019 20:13
Star
You must be signed in to star a gist
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.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