-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.StorageFactory.sol
40 lines (24 loc) · 1.59 KB
/
2.StorageFactory.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// SPDX-License_Identifier : MIT
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.9.0;
import "./simpleStorage.sol" ; //as we want to create a contract which creates a simple storgae contracts.
contract StorageFactory is SimpleStorage{ // Inheritance we inherited simple storage to Storagefactory.
SimpleStorage[] public SimpleStorageContractarray; // to store all the new creating contracts.
function CreateSimpleStorageContract() public {
// here we are create new objects of SimpleStorage contract which takes no arguments.
SimpleStorage SimpleStorageNewContract = new SimpleStorage();
SimpleStorageContractarray.push(SimpleStorageNewContract);
}
// now we need to interact with the contracts we are creating.
// fornthis we need the address of the contract we want to interact with .
// we also need ABI which we get from the import file.
function sfStore(uint256 contractIndex , uint256 contractNumber) public {
// here we need contractIndex to get the index at which our contract addess is present.
// and contractNumber to pass the fovorie number on simple storage file.
SimpleStorage SimpleStorage = SimpleStorage(address(SimpleStorageContractarray[contractIndex])); // here we are retriving the address and interact with simple storage contact.
SimpleStorage.store(contractNumber);
}
function sfGet(uint contractIndex) public view returns(uint256) {
return SimpleStorage(address(SimpleStorageContractarray[contractIndex])).retrieve();
}
}