Skip to content

Instantly share code, notes, and snippets.

@Scofield-Idehen
Created December 13, 2023 12:50
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 Scofield-Idehen/bca5c823488c7cb3b22aa834fbe8054f to your computer and use it in GitHub Desktop.
Save Scofield-Idehen/bca5c823488c7cb3b22aa834fbe8054f 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.22+commit.4fc1097e.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
import {scofield} from "./new1.sol";
contract addinherietance is scofield{
function store(uint _addnewfive) public override {
number = _addnewfive +5;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18; // solidity version
contract scofield {
//number gets initialized to zero if no number is added
uint public number;
mapping (string => uint256) public findname;
//array of numbers
//uint [] array_number;
struct Person{
uint new_number;
string name;
}
//static and dynamic array
Person[] public scofieldArray;
// this adds a new item to the list of the array!!!
// Person public scofield = Person({new_number: 9, name: "valencia"});
function store (uint _number) public virtual {
number = _number;
}
// view pure disallow updating the state of the function
function retrieve() public view returns (uint){
return number;
}
//this function takes the array and adds a new user to the list, name.push
//to the struct Person
//so you say name.push(struct of the values equals to what is inside the struct
function addnew(string memory _name, uint _new_number) public {
scofieldArray.push(Person(_new_number, _name));
findname[_name] = _new_number;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import {testing} from './test.sol';
contract advancetest{
testing public Test;
function testcon() public {
Test = new testing();
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
// this only import the exact contract and do not import like this
// import './new1.sol';
import {scofield} from "./new1.sol";
contract update_contract{
// this would not keep track of all the contract so we need to make it an array
//contract veraible
//scofield public Scofield;
scofield[] public listofScofieldcontract;
function get_new_contract() public{
scofield newlist = new scofield();
listofScofieldcontract.push(newlist);
}
function store (uint _index, uint storeNumber) public {
listofScofieldcontract[_index].store(storeNumber);
}
function getValue(uint _storeindex) public view returns (uint){
return listofScofieldcontract[_storeindex].retrieve();
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
contract testing{
struct Person{
string name;
uint valueNumber;
}
Person[] public NewPerson;
mapping (string => uint) public new_map;
function listname(string memory _name, uint _valueNumber) public {
NewPerson.push(Person(_name, _valueNumber));
new_map[_name]= _valueNumber;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment