How to read data from my other contract(s) storage?

Hello fellow developers,

I currently have a main contract which does all the computation and generation of NFT traits.

However, all of the encoded image layers are stored in 4-5 other contracts. Each of this contracts, including the main contract, must be deployed separately because they cost too much gas to be deployed together.

I have no idea how to link them up on deployment and in code, so as to allow my main contract to read the other contracts' storage. (Read only)

Do I simply use the import function at the start of my contract, or use the is inheritance function?

Thank you!

I managed to solve this.

So what I did was to create an interface in the main contract that you want to read in. Then, create an instance of the storage contract with the interface. After which, simply call the getter function and you you'll be able read the data from the storage contract.

Main contract

interface IStorage {

function getLayer(uint256 index) external view returns (string memory);
// You can also do a setter method here. It's totally up to you


contract Main {

address storageAddr = 0x123;

function genSVG(uint256 tokenId) internal view returns (string memory) {
string memory layer = IStorage(storageAddr).getLayer(index);


Storage contract

contract ImageStorage {

mapping(uint256 => string) public layer;

layer[0] = "...";
layer[1] = "...";
layer[2] = "...";
layer[3] = "...";

function getLayer(uint256 index) external view returns (string memory) {
return layer[index];

// You can also add your setter function here