Let's say there is a uint[] public MyArray declared in contract_A.

Is there a possiblility to create an interface contract_A that would allow to read the values in MyArray from another contract, or is it absolutely necessary to build a getter for MyArray in contract_A?

Asking this because of the code size limit, if there are a lot of arrays in contract_A, would be convenient to not build a getter for all of them (they need to be read by another contract).


All public variables automatically generate a getter function so you don't need to explicitly create new ones.

Here is an example:

pragma solidity >=0.5.0;

contract A {
     uint[1] public MyArray;
     constructor() public {
         MyArray[0] = 56;
contract B {
    function DoIt() public returns (uint) {
        A contr = new A();
        return contr.MyArray(0);

You should deploy contract B and call its DoIt function to get result 56.

  • Thank you. When doing new A(), does it create a new instance of contract A? Is there a way to point to an already existing contract A?
    – Thomas
    Dec 20 '20 at 16:34
  • Yes, it creates a new instance. You can point to an existing A with A contr = A(addressOfA); Dec 20 '20 at 17:00
  • perfect, thank you.
    – Thomas
    Dec 20 '20 at 17:23

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.