Skip to content

Instantly share code, notes, and snippets.

@jigar23
Created May 15, 2018 16:07
Show Gist options
  • Save jigar23/902e273a44142f0cf92871e1d14f44c0 to your computer and use it in GitHub Desktop.
Save jigar23/902e273a44142f0cf92871e1d14f44c0 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.4.23+commit.124ca40d.js&optimize=false&gist=
pragma solidity ^0.4.0;
// Pure Virtual class
interface Regulator {
function checkValue(uint amount) returns (bool);
function loan() returns (bool);
}
// Inheriting Regulator
contract Bank is Regulator {
uint private value;
// Parameterized Constructor
function Bank(uint amount) {
value = amount;
}
function deposit(uint amount) {
value += amount;
}
function withdraw(uint amount) {
if (checkValue(amount)) {
value -= amount;
}
// error handling later
}
function balance() returns (uint) {
return value;
}
function checkValue(uint amount) returns (bool) {
return value >= amount;
}
function loan() returns (bool) {
return value > 0;
}
}
// Inheriting Bank
contract MyFirstContract is Bank(10) {
string private name;
uint private age;
// Can use var newName but that by default will take 256 bits
function setName(string newName) public {
name = newName;
}
function getName() public view returns (string) {
return name;
}
function setAge(uint newAge) public {
age= newAge;
}
function getAge() public view returns (uint) {
return age;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment