Created
May 3, 2022 14:40
-
-
Save derawl/a88e19593ddb56c64868efa6b84ebce8 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.6.12+commit.27d51765.js&optimize=false&runs=200&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.6.0; | |
import "./SimpleStorage.sol"; | |
contract SimpleStorageFactory is SimpleStorage{ | |
//goals | |
//Create instances of the simple storage contract | |
//To allow users to interact with the various instances | |
//Users can store and retrieve data from individual contracts\ | |
//This array allows us to store instances of the simple storage contract | |
SimpleStorage[] public simpleStorageContracts; | |
mapping(address=>SimpleStorage) public deployerToContract; | |
function createNewInstances() public{ | |
//Task 1 | |
//Create a new instance of the contract | |
SimpleStorage simpleStorageContractsInstance = new SimpleStorage(); | |
//Push the details of the deployed instance to the array | |
simpleStorageContracts.push(simpleStorageContractsInstance); | |
deployerToContract[msg.sender] = simpleStorageContractsInstance; | |
} | |
//interaction functions | |
function allowInstanceToAddPerson(address deployer, uint256 _favouriteNumber, string memory _name) public{ | |
SimpleStorage mySimpleStorageContract = SimpleStorage(deployerToContract[deployer]); | |
mySimpleStorageContract.addPerson(_favouriteNumber, _name); | |
} | |
function retrieveDataFromInstance(address deployer, string memory _name) public returns(uint256){ | |
SimpleStorage mySimpleStorageContract = SimpleStorage(deployerToContract[deployer]); | |
uint256 favouriteNumber = mySimpleStorageContract.retrieve(_name); | |
return favouriteNumber; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment