new to solidity.
Trying to understand the better approach for using a mapping
storage in factory contract.
2 options:
- Use
mapping(address => Contract[])
- Use
mapping(address => address[])
Sample factory:
contract CampaignFactory {
mapping(address => Campaign[]) campaigns;
function createCampaign(uint min_contrib) public {
Campaign newCampaign = new Campaign(min_contrib, msg.sender);
campaigns[msg.sender].push(newCampaign);
}
function getCampaignsByAddress(address creator) public view returns (Campaign[] memory) {
return campaigns[creator];
}
}
As i understand, the first option suppose to use more storage space to store the whole contract instance.
However, for both options createCampaign
cost (remix estimation) is the same +- 660000
gas.
Additionally, getCampaignsByAddress
with the return type Campaign[]
strangely returns only addresses instead of full instances (so i suppose only the address is stored).
Question: what difference does it make to use option #1 or #2?