Skip to content

Instantly share code, notes, and snippets.

@selevit
Created February 19, 2020 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save selevit/906b4d7387cb6c3122625c752dd3e898 to your computer and use it in GitHub Desktop.
Save selevit/906b4d7387cb6c3122625c752dd3e898 to your computer and use it in GitHub Desktop.
An Ethereum smart contract which transfers many different ERC20 tokens and ETH in one transaction
pragma solidity >=0.4.21 <0.7.0;
pragma experimental ABIEncoderV2;
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
contract MultiTransfer {
struct Destination {
address token;
uint256 amount;
address payable receiver;
}
function() external payable {}
function send(Destination[] memory destinations) public payable returns (bool success) {
for (uint256 x = 0; x < destinations.length; x++) {
Destination memory dst = destinations[x];
if (dst.token == 0x000000000000000000000000000000000000bEEF) {
// Eth transfer
dst.receiver.transfer(dst.amount);
} else {
ERC20 erc20_contract = ERC20(dst.token);
assert (erc20_contract.transferFrom(msg.sender, dst.receiver, dst.amount));
}
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment