Skip to content

Instantly share code, notes, and snippets.

@nodlAndHodl
Created February 5, 2022 03:46
Show Gist options
  • Save nodlAndHodl/2cd3d08b377e19162dae90f1e806bad6 to your computer and use it in GitHub Desktop.
Save nodlAndHodl/2cd3d08b377e19162dae90f1e806bad6 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.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract MainContract {
uint public value;
constructor (uint amount) {
value = amount;
}
function deposit (uint amount) public {
value += amount;
}
function withdraw (uint amount) public {
value -= amount;
}
}
interface ContractInterface {
function sendMoney (uint amount, address payable _address) external returns (bool);
}
// This will give an error...since baseContract has a constructor that we need to initialize
// contract myContract is baseContract, interfaceContract {
contract InheritanceContract is ContractInterface, MainContract(100) {
string public contractName;
uint public balanceReceived;
constructor (string memory _n) {
contractName = _n;
}
function getValue () public view returns (uint) {
//value comes from inerited contract
return value;
}
// This function has to be implemented, since it is unimplemented in the interfaceContract
function sendMoney (uint amount, address payable _address) public override returns (bool) {
address payable to = payable(_address);
to.transfer(amount);
return true;
}
function payContractMoney() public payable {
balanceReceived += msg.value;
}
function getBalance() public view returns(uint) {
return address(this).balance;
}
function withdrawMoney() public {
address payable to = payable(msg.sender);
to.transfer(getBalance());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment