1

Pretty straight forward: is there any way for a contract to send tokens only to addresses with non-zero (or with a minimum required amount) ETH addresses?

I have this function to send tokens to multiple addresses:

function distributeToken(address[] addresses, uint256 _value) onlyOwner {
     for (uint i = 0; i < addresses.length; i++) {
         balances[owner] -= _value;
         balances[addresses[i]] += _value;
         Transfer(owner, addresses[i], _value);
     }
}

but I'm trying to add a require for non-zero balance. I changed it this way, so it should check if the receiver got at least 0.01 ETH:

function getEthBalance(address _addr, uint userBalance) constant returns(uint) {
return _addr.balance;
userBalance = _addr.balance;
}

function distributeToken(address[] addresses, uint256 _value, uint userBalance) onlyOwner {
 require(userBalance >= 10000000000000000);
     for (uint i = 0; i < addresses.length; i++) {
         balances[owner] -= _value;
         balances[addresses[i]] += _value;
         Transfer(owner, addresses[i], _value);
     }
}

but it doesn't work properly. Sorry but I'm new to solidity and I'm still learning it. Thank you for you helping and patience.

1 Answer 1

1

Your understanding of how to get the balance looks fine, your problem is the way you're trying to use functions and return values.

If the goal is to do this check when distributeFUD is called, you'll need to actual call your getEthBalance() function in there.

First remove the extraneous parts that aren't actually involved in returning a value:

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

Then in you presumably want to check it inside your for loop, eg

require(getEthBalance(addresses[i]) > 10000000000000000));

If if you just want to skip addresses without enough balance rather than just blowing up, you might prefer,

if (getEthBalance(addresses[i]) <= 10000000000000000)) {
    continue;
}
1
  • Well, that's the same way to use the continue statement as in javascript, shame on me to had not think about it! this is working as expected, thank you very much!
    – user19489
    Oct 6, 2017 at 6:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.