Skip to content

Instantly share code, notes, and snippets.

@dhananjayhegde
Created December 5, 2021 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhananjayhegde/efa7c3fce6a24a669a2a4e3bf48d7e56 to your computer and use it in GitHub Desktop.
Save dhananjayhegde/efa7c3fce6a24a669a2a4e3bf48d7e56 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.8.1+commit.df193b15.js&optimize=undefined&runs=undefined&gist=
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.1;
import "./SimpleStorage.sol";
// This is a contract that will let you create and deploy SimpleStorage contracts
// A Contract that creates other contracts - Contract Factory
// In the end, we also inherited SimpleStorage here so that
// SimpleStorageFactory gets all functionalities of SimpleStorage
contract StorageFactory is SimpleStorage{
SimpleStorage[] public simpleStorageArray;
function createSimpleStorageContract() public {
SimpleStorage simpleStorage = new SimpleStorage();
simpleStorageArray.push( simpleStorage );
}
// Store something to simple Storage contract that is deployed using above function
function sfStore(uint256 _simpleStorageIndex, uint256 _simpleStorageNumber) public{
// Address of SimpleStorage contract instance
// ABI - Application Binary Interface
// Get the simple storage contract ABI that we need to interact using the address
SimpleStorage( address( simpleStorageArray[ _simpleStorageIndex ] ) ).store( _simpleStorageNumber );
}
function sfGet( uint256 _simpleStorageIndex ) public view returns( uint256 ) {
return SimpleStorage( address( simpleStorageArray[ _simpleStorageIndex ] ) ).retrieve();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment