I'm trying to modify a standard ERC20 token to send the same value to multiple addresses like so:

function transferToMultipleAccounts(address[] _to, uint256 _value) public returns (bool) {

    for (uint i = 0; i < _to.length; i++) {
        transfer(_to[i], _value);

    return true;

I've gota truffle unit test for it:

let accountsToReceive = [accounts[6], accounts[7], accounts[8], accounts[9]]
      let txHash = await token.transferToMultipleAccounts(2, accountsToReceive)

but when I run the unit test I get this error:

 TypeError: value.forEach is not a function

If I remove the loop everything works fine, but when I put the loop back I get that error. Any idea what I'm doing wrong?



Check the order of your parameters. It should be:

let txHash = await token.transferToMultipleAccounts(accountsToReceive, 2)
| improve this answer | |

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.