0

The code below is for illustrative purposes only. Not the actual production code.

function payCommission(address[] payee) public payable {
    for (uint i = 0; i < payee.length; i++)
        payee[i].transfer(0.001 ether);
}

Recently I encountered some very strange failure, which I cannot explain at all. The only possible failure mode is solidity prohibit sending two transactions to similar address within one transaction. (Example, there are two same address in the payee array).

I have tested in my private node, but that is not the case, is it just changed recently? If yes, which version?

Thanks

  • 1
    The only possible failure mode is solidity prohibit sending two transactions to similar address within one transaction - how can we comment on that when without seeing your solidity function code, your transaction code of executing it (for example, via web3.js), and the exact error that you got for it??? This is simply your interpretation of what you saw, and that interpretation sounds wrong (there is no such restriction AFFAIK). – goodvibration Aug 6 at 3:35
  • @goodvibration, that for the answer. As usual, solidity doesn't gives any error code other than the Transaction Status = 0, that is why I am still figuring out what might have gone wrong. The original solidity code is must more complicated than the above. Anyway, thanks for confirming that there is so such restriction. I will continue to look somewhere else. – s k Aug 8 at 4:15
3

Solidity arrays are zero-based. If you run this code with two addresses, it will only run once, since you initialize i with 1. This means that the for-loop will stop after one iteration (assuming payee.length = 2). If you change the loop to start from 0, it will work:

  function payCommission (address payable[] memory payee) public payable {
    for (uint i = 0; i < payee.length; i++) {
       payee[i].transfer(0.001 ether);
     }
   }
| improve this answer | |
  • sorry for the mistakes, it was a typo. I will rectify it – s k Aug 8 at 4:12

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.