Skip to content

Instantly share code, notes, and snippets.

@daiki44
Created August 12, 2018 13:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daiki44/eaec3d48da1838fcd36ea5259f303f84 to your computer and use it in GitHub Desktop.
Save daiki44/eaec3d48da1838fcd36ea5259f303f84 to your computer and use it in GitHub Desktop.
【Solidity】TypeError: Member “push” is not available in address[] memory outside of storage. ref: https://daiki-sekiguchi.com/2018/08/12/ethereum-solidity-member-push-is-not-available-in-address-memory-outside-of-storage/
pragma solidity ^0.4.24;
contract ExampleContract {
function example(address _address) public view returns (address[]) {
address[] addressList;
for (uint i = 0; i < 100; i++) {
// memory で定義された配列は可変長の配列として扱えないためエラーが発生する
addressList.push(_address);
}
return addressList;
}
}
@dafei-ning
Copy link

contract ExampleContract {
  address[] addressList;
  function example(address _address) public view returns (address[]) {
      address[] memory tempAddrlist;
      addressList = tempAddrlist;
      for (uint i = 0; i < 100; i++) {
        addressList.push(_address);
      }
      return addressList;
  }
}

I always implement like this...

@opleno
Copy link

opleno commented May 20, 2019

Hi @jackningdl, this works in old solidity compiler versions but not in newer ones, since you're declaring a "view" function that potentially modifies storage.
Is there a solution where "view" modifier can be used?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment