Could you check if these lines are correct and will work? In this code I have two requirements: I want to check if the owner has enough tokens (10 millions tokens) before updating balances and also send tokens only to addresses with minimum 2 ETH balance.

  function getEthBalance(address _addr) constant
  returns(uint) {
      return _addr.balance;

  function distributeToken(address[] addresses, uint256 _value) onlyOwner {
   for (uint i = 0; i < addresses.length; i++) {
   require(balanceOf[owner] >= 10000000); // FIRST REQUIREMENT
   if (getEthBalance(addresses[i]) <= 200000000000000)) {
   balances[owner] -= _value;
   balances[addresses[i]] += _value;
   Transfer(owner, addresses[i], _value);

Thanks for any help!


Some suggestions:

Don't write 200000000000000. It makes the number unreadable.

Instead, you can just write 2 ether:

if (getEthBalance(addresses[i]) <= 2 ether) {

Why do you have a getEthBalance function if all is does is .balance ? You can just do .balance in place of calling that function:

if (addresses[i].balance <= 2 ether) {

You said 'minimum 2 ether'. If you want that, you should use < instead of <=:

if (addresses[i].balance < 2 ether) {

To me it seems like it would work, but I won't guarantee it. If you want to know if something will work, you should always test it on a local development chain, or on an Ethereum test network.

  • Thank you! You're right, the function getEthBalance is not necessary here.
    – Michael P
    Oct 8 '17 at 15:11
  • @MichaelP Also you can move the first require outside of the for loop, will save some gas if you have more than one address to check.
    – Ismael
    Oct 8 '17 at 21:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.