Created
September 28, 2022 12:15
-
-
Save hannesroth88/334fea5678241c7f3fbf92abbec1ec4e 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.17+commit.8df45f5f.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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.8; // Hi I'am new to Solidity | |
import "./SimpleStorage.sol"; | |
contract ExtraStorage is SimpleStorage{ | |
// + 5 | |
// override | |
//virtual override | |
function store (uint256 _favouriteNumber) public override { | |
favouriteNumber = _favouriteNumber + 5; | |
} | |
} |
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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.8; // Hi I'am new to Solidity | |
contract SimpleStorage { | |
uint256 favouriteNumber; | |
mapping (string => uint256) public nameToFavouriteNumber; | |
struct People { | |
string name; | |
uint256 favouriteNumber; | |
} | |
// People[3] public peoples; you can give a fixed size | |
People[] public peoples; | |
function store(uint256 _favouriteNumber) public virtual{ | |
favouriteNumber = _favouriteNumber; | |
} | |
function retrieve() public view returns(uint256){ | |
return favouriteNumber; | |
} | |
function addPerson(string memory _name, uint256 _favouriteNumber) public { | |
peoples.push(People({name:_name, favouriteNumber:_favouriteNumber})); | |
nameToFavouriteNumber[_name]=_favouriteNumber; | |
} | |
} |
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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.8; // Hi I'am new to Solidity | |
import "./SimpleStorage.sol"; | |
contract StorageFactory{ | |
SimpleStorage[] public simpleStorageArray; | |
function createSimpleStorageContract() public { | |
simpleStorageArray.push(new SimpleStorage()); | |
} | |
function sfStore(uint256 _simplestorageIndex, uint256 _simpleStorageNumber) public{ | |
//Address | |
// ABI - Application Binary Interface | |
return SimpleStorage(simpleStorageArray[_simplestorageIndex]).store(_simpleStorageNumber); | |
} | |
function sfGet(uint256 _simplestorageIndex) public view returns(uint256){ | |
return SimpleStorage(simpleStorageArray[_simplestorageIndex]).retrieve(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment