Skip to content

Instantly share code, notes, and snippets.

@amiraliakbari
Created October 27, 2020 13:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amiraliakbari/c112633bc90986db7970b17004fd663b to your computer and use it in GitHub Desktop.
Save amiraliakbari/c112633bc90986db7970b17004fd663b to your computer and use it in GitHub Desktop.
Tron Multi-send contract
pragma solidity ^0.5.0;
/**
* SPDX-License-Identifier: UNLICENSED
*/
/**
* @title SafeMath
* @dev Math operations with safety checks that revert on error
*/
library SafeMath {
/**
* @dev Multiplies two numbers, reverts on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers truncating the quotient, reverts on division by zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0); // Solidity only automatically asserts when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a);
uint256 c = a - b;
return c;
}
/**
* @dev Adds two numbers, reverts on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);
return c;
}
/**
* @dev Divides two numbers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
}
contract Token {
uint8 public decimals;
function transfer(address _to, uint256 _value) public returns (bool success);
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success);
function allowance(address _owner, address _spender) public view returns (uint256 remaining);
}
contract TrxMultiSend {
using SafeMath for uint256;
address public owner;
uint public tokenSendFee; // in wei
uint public ethSendFee; // in wei
constructor() public payable{
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
function bulkSendTrx(address payable[] memory addresses, uint256[] memory amounts) public payable returns(bool success){
uint total = 0;
for(uint8 i = 0; i < amounts.length; i++){
total = total.add(amounts[i]);
}
//ensure that the ethreum is enough to complete the transaction
uint requiredAmount = total.add(ethSendFee * 1 sun); //.add(total.div(100));
require(msg.value >= (requiredAmount * 1 sun));
//transfer to each address
for (uint8 j = 0; j < addresses.length; j++) {
addresses[j].transfer(amounts[j] * 1 sun);
}
//return change to the sender
if(msg.value * 1 sun > requiredAmount * 1 sun){
uint change = msg.value.sub(requiredAmount);
msg.sender.transfer(change * 1 sun);
}
return true;
}
function getbalance(address addr) public view returns (uint value){
return addr.balance;
}
function deposit() payable public returns (bool){
return true;
}
function withdrawEther(address payable addr, uint amount) public onlyOwner returns(bool success){
addr.transfer(amount * 1 sun);
return true;
}
function destroy (address payable _to) public onlyOwner {
selfdestruct(_to);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment