Last active
January 19, 2022 01:26
-
-
Save sumitpatel93/ae53b1b65f0830891da04110215f6bd9 to your computer and use it in GitHub Desktop.
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
//["add1","add2,"add3","add4",....."add10"] | |
//["123","333","22","333","121","222","2323","33","232","222"] | |
/** | |
Following are the obsevations recorded | |
total trx cost in a single transactions: | |
=> 0.0001207437 | |
trx cost to distribute token in separate calls = 0.0000567105+0.00005669202+0.00005669202+0.0000567105+0.0000567105+0.00005669202+0.00005669202+0.00008300754+0.00008302602+0.00008302602 | |
=> 0.00064595916 | |
trx link : https://kovan.etherscan.io/token/0xcfba8257001d21cc05b11837c232c9503595d91a | |
**/ | |
//set admin instead of owner in the distribute function or else the token will be distributed from 0x00 that is default address, when address is not set | |
pragma solidity ^0.4.8; | |
contract admined { | |
address public admin; | |
function admined() public { | |
admin = msg.sender; | |
} | |
modifier onlyAdmin(){ | |
require(msg.sender == admin) ; | |
_; | |
} | |
function transferAdminship(address newAdmin) onlyAdmin public { | |
admin = newAdmin; | |
} | |
} | |
contract TCoin { | |
mapping (address => uint256) public balanceOf; | |
mapping (address => mapping (address => uint256)) public allowance; | |
// balanceOf[address] = 5; | |
string public standard = "TCoin v1.0"; | |
string public name; | |
string public symbol; | |
uint8 public decimals; | |
uint256 public totalSupply; | |
event Transfer(address indexed from, address indexed to, uint256 value); | |
function TCoin(uint256 initialSupply, string tokenName, string tokenSymbol, uint8 decimalUnits) public { | |
balanceOf[msg.sender] = initialSupply; | |
totalSupply = initialSupply; | |
decimals = decimalUnits; | |
symbol = tokenSymbol; | |
name = tokenName; | |
} | |
function transfer(address _to, uint256 _value) public { | |
require(balanceOf[msg.sender] > _value) ; | |
require(balanceOf[_to] + _value > balanceOf[_to]) ; | |
balanceOf[msg.sender] -= _value; | |
balanceOf[_to] += _value; | |
Transfer(msg.sender, _to, _value); | |
} | |
function approve(address _spender, uint256 _value) public returns (bool success){ | |
allowance[msg.sender][_spender] = _value; | |
return true; | |
} | |
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success){ | |
require(balanceOf[_from] > _value) ; | |
require(balanceOf[_to] + _value > balanceOf[_to]) ; | |
require(_value < allowance[_from][msg.sender]) ; | |
balanceOf[_from] -= _value; | |
balanceOf[_to] += _value; | |
allowance[_from][msg.sender] -= _value; | |
Transfer(_from, _to, _value); | |
return true; | |
} | |
} | |
contract TCoinAdvanced is admined, TCoin{ | |
uint256 minimumBalanceForAccounts = 5 finney; | |
uint256 public sellPrice; | |
uint256 public buyPrice; | |
mapping (address => bool) public frozenAccount; | |
event FrozenFund(address target, bool frozen); | |
function TCoinAdvanced(uint256 initialSupply, string tokenName, string tokenSymbol, uint8 decimalUnits, address centralAdmin) TCoin (0, tokenName, tokenSymbol, decimalUnits ) public { | |
if(centralAdmin != 0) | |
admin = centralAdmin; | |
else | |
admin = msg.sender; | |
balanceOf[admin] = initialSupply; | |
totalSupply = initialSupply; | |
} | |
function transfer(address _to, uint256 _value) public { | |
if(msg.sender.balance < minimumBalanceForAccounts) | |
require(frozenAccount[msg.sender]) ; | |
require(balanceOf[msg.sender] > _value) ; | |
require(balanceOf[_to] + _value > balanceOf[_to]) ; | |
balanceOf[msg.sender] -= _value; | |
balanceOf[_to] += _value; | |
Transfer(msg.sender, _to, _value); | |
} | |
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { | |
require(frozenAccount[_from]) ; | |
require(balanceOf[_from] > _value) ; | |
require(balanceOf[_to] + _value > balanceOf[_to]) ; | |
require(_value < allowance[_from][msg.sender]) ; | |
balanceOf[_from] -= _value; | |
balanceOf[_to] += _value; | |
allowance[_from][msg.sender] -= _value; | |
Transfer(_from, _to, _value); | |
return true; | |
} | |
function owned() { owner = msg.sender; } | |
address owner; | |
function distributeToken(address[] addresses, uint256 _value) onlyAdmin { | |
for( uint256 i=0;i<addresses.length;i++){ | |
balanceOf[owner] -= _value; | |
balanceOf[addresses[i]] += _value; | |
Transfer(owner, addresses[i], _value); | |
} | |
} | |
} |
one, so yes it will save gas, but possible cost more gas
@adityataday it does saves cost. check the top of gist for info.
one, so yes it will save gas, but possible cost more gas
it does saves cost.
If you pass the same address twice in one tx, will it appear with different outputs or will it consolidate it naturally?
balanceOf[owner] -= _value;
move this line from for loop
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does it send all the tokens in a single transaction or multiple transactions? Will this help to save gas?