Skip to content

Commit a5534c7

Browse files
authored
Create Person.cdc
1 parent 9df55cc commit a5534c7

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

cadence/contracts/Person.cdc

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// A simple Person contract
2+
//
3+
// reference: https://developers.flow.com/cadence/language/contracts
4+
pub contract Person {
5+
// declaration of a public variable
6+
pub var name: String
7+
// declaration of a private variable, reference: https://developers.flow.com/cadence/language/access-control#access-control
8+
access(self) var mood: Mood
9+
10+
// Enums type declaration, reference: https://developers.flow.com/cadence/language/enumerations#enum-declaration
11+
pub enum Mood: UInt8 {
12+
pub case happy
13+
pub case angry
14+
pub case melanholic
15+
}
16+
17+
// initialization method for our contracts, this gets run on deployment
18+
init() {
19+
self.name = "Alice"
20+
self.mood = Mood.happy
21+
}
22+
23+
pub fun hello(): String {
24+
log("saying hello") // when we log we can see the log in the emulator output, helpful for debugging
25+
26+
switch self.mood {
27+
case Mood.happy:
28+
return "😍 Hello!"
29+
case Mood.angry:
30+
return "😤 Go away!"
31+
case Mood.melanholic:
32+
return "😐 Hi I guess?"
33+
default:
34+
return "💩 Not sure!"
35+
}
36+
}
37+
38+
pub fun WhoAmI(): String {
39+
return "I am ".concat(self.name)
40+
}
41+
42+
// set a new name
43+
pub fun setName(name: String) {
44+
self.name = name
45+
}
46+
47+
// Friendship resource are types of values that can only exist in one place
48+
//
49+
// read more about this unique and powerful Cadence feature here https://developers.flow.com/cadence/language/resources
50+
pub resource Friendship {
51+
52+
}
53+
54+
}
55+
56+

0 commit comments

Comments
 (0)