[Ethereum] How to call solidity function which has array of address as an argument using web3

javascriptsolidityweb3js

Say i have a contract as follows:

contract A {
  function passAddress(address[] _addr) {
    // do something
  }
}

How do i call this function in my frontend application using web3.
I tried using javascript array but it throws revert exception.

Any ideas ?

Best Answer

You are only able to pass datatypes which the contract recognises, so passing a javascript array is not an option.

If you have an array of all your addresses, you could try joining them using javascript, and passing the resulting string using web3. ie,

if you have

array = [0x0,0x0,0x0];

and you made that

string = '["0x0","0x0","0x0"]'

and pass that string as the "array" then that could do the trick