-
Notifications
You must be signed in to change notification settings - Fork 603
Expand file tree
/
Copy pathmyfirstcontract.sol
More file actions
52 lines (46 loc) · 1.22 KB
/
myfirstcontract.sol
File metadata and controls
52 lines (46 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
pragma solidity ^0.7.0;
interface Regulator{
function checkValue(uint amount) external returns (bool);
function loan() external returns (bool);
}
contract Bank is Regulator {
uint private value;
constructor(uint amount) {
value = amount;
}
function deposit(uint amount) public {
value += amount;
}
function withdraw(uint amount) public {
if (checkValue(amount)) {
value -= amount;
}
}
function balance() public view returns (uint) {
return value;
}
function checkValue(uint amount) override view public returns (bool) {
// Classic mistake in the tutorial value should be above the amount
return value >= amount;
}
function loan() override view public returns (bool) {
return value > 0;
}
}
// Tutorial 01
contract myFirstContract is Bank(10) {
string private name;
uint private age;
function setName(string memory newName) public {
name = newName;
}
function setAge(uint newAge) public {
age = newAge;
}
function getName() public view returns (string memory) {
return name;
}
function getAge() public view returns (uint) {
return age;
}
}