Contact type array returning address value

Below is the contract which imports another contract

pragma solidity ^0.8.7;

import "./SimpleStorage.sol"; 

contract StorageFactory {

   SimpleStorage[] public simpleStorageArray;    
   function createSimpleStorageContract() public {
       SimpleStorage simpleStorage = new SimpleStorage();

Now after using function createSimpleStorageContract() and trying to fetch elements of array , we are seeing

SimpleStorage is another contract which I wrote and then imported it. Now simpleStorageArray is an array of type SimpleStorage. However what I am not able to understand which I try to fetch any value by providing index number in remix , it returns me the address. In every element it should store a new instance of contract why is it storing addresses. Can anyone please explain if array is of SimpleStorage contract type then why it stores & returns address when given index number ?

Because what you get from new is the address of the created contract

1 Like

I think new creates a new instance , how does it return address ?

Creating a new instance like that will deploy a new contract. so you receive the returned contract address when you created the instance.
With that address you can then use your interface to call the functions on it to retrieve your data

1 Like