I am failing to use the push method against a dynamic array declared as a state variable. How can I do this?

I declare a dynamic array of addresses as a state variable like below:

contract Sample {
  address[] public path;

Then, inside a function of this contract, I push two addresses into the dynamic array:

path.push(address1, address2);

And I get this compile error:

CompileError: Sample.sol:91:9: TypeError: Member "push" not found or not visible after argument-dependent lookup in address[] storage ref.
        path.push(address1, address2);
  • 2
    I admit that this error-message is indeed confusing, and that it doesn't imply to the problem in your code. Nevertheless, you should push each address separately, as push does not support multiple values at once. Nov 5 '20 at 12:27

You can only push one item at a time. In your case, simply split up your function:


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.