-
Notifications
You must be signed in to change notification settings - Fork 26
/
01-the-deployable-trait.html
165 lines (138 loc) · 7.6 KB
/
01-the-deployable-trait.html
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="robots" content="index,follow" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>Tact by example</title>
<meta name="description" content="Learn smart contract programming by example using Tact language" />
<link rel="canonical" href="https://tact-by-example.org/" />
<meta property="og:title" content="tact by example" />
<meta property="og:type" content="website" />
<meta property="og:description" content="Learn smart contract programming by example using Tact language" />
<meta property="og:url" content="https://tact-by-example.org/" />
<link rel="shortcut icon" href="favicon.png" type="image/x-icon" />
<!--
<link
rel="apple-touch-icon"
sizes="180x180"
href="/favicons/apple-touch-icon.png"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="/favicons/favicon-32x32.png"
/>
<link
rel="icon"
type="image/png"
sizes="16x16"
href="/favicons/favicon-16x16.png"
/>
-->
<meta http-equiv="content-security-policy" content="">
<link href="./_app/immutable/assets/_layout.e2caa7e1.css" rel="stylesheet">
<link href="./_app/immutable/assets/app.8bddbbc4.css" rel="stylesheet">
<link rel="modulepreload" href="./_app/immutable/entry/start.b5438541.js">
<link rel="modulepreload" href="./_app/immutable/chunks/index.9fe14626.js">
<link rel="modulepreload" href="./_app/immutable/chunks/singletons.25c14d13.js">
<link rel="modulepreload" href="./_app/immutable/chunks/index.1c761ed5.js">
<link rel="modulepreload" href="./_app/immutable/entry/app.06a021a8.js">
<link rel="modulepreload" href="./_app/immutable/entry/layout.svelte.2cd9eabd.js">
<link rel="modulepreload" href="./_app/immutable/entry/_layout.ts.984db11e.js">
<link rel="modulepreload" href="./_app/immutable/chunks/_layout.da46b06b.js">
<link rel="modulepreload" href="./_app/immutable/entry/(examples)-layout.svelte.01f6cb21.js">
<link rel="modulepreload" href="./_app/immutable/chunks/store.476c3091.js">
<link rel="modulepreload" href="./_app/immutable/chunks/examples.ec427188.js">
<link rel="modulepreload" href="./_app/immutable/chunks/app.cf8f4105.js">
<link rel="modulepreload" href="./_app/immutable/entry/(examples)-01-the-deployable-trait-page.svelte.cab4baf4.js">
<link rel="modulepreload" href="./_app/immutable/chunks/index.c056099e.js">
</head>
<body>
<div style="display: contents">
<div class="pageLoader"><div class="sk-folding-cube"><div class="sk-cube1 sk-cube"></div>
<div class="sk-cube2 sk-cube"></div>
<div class="sk-cube4 sk-cube"></div>
<div class="sk-cube3 sk-cube"></div></div></div>
<div class="split vertical svelte-9dft0e" style="--primary-size:47%;--min-primary-size:0;--min-secondary-size:0;--splitter-size:7px"><div class="primary svelte-9dft0e"><div slot="primary" class="panelMarkdown" style="position: absolute; top: 0; bottom: 0; left: 0; right: 0; overflow: scroll;"><!-- HTML_TAG_START --><h1 id="a-simple-counter">A Simple Counter</h1>
<p>This is a simple counter contract that allows users to increment its value.</p>
<p>This contract has a state variable <code>val</code> that persists between contract calls - the counter value. When persisted, this variable is encoded <code>as uint32</code> - a 32-bit unsigned integer. Contracts pay rent in proportion to the amount of persistent space they consume, so compact representations are encouraged.</p>
<p>State variables should be initialized in <code>init()</code> that runs on deployment of the contract.</p>
<h2 id="receiving-messages">Receiving messages</h2>
<p>This contract can receive <strong><em>messages</em></strong> from users.</p>
<p>Unlike getters that are just read-only, messages can do write operations and change the contract's persistent state. Incoming messages are processed in <code>receive()</code> methods as transactions and cost gas for the sender.</p>
<p>After deploying the contract, send the <code>increment</code> message by pressing the <span class="mdButton grape">Send increment</span> button in order to increase the counter value by one. Afterwards, call the getter <code>value()</code> to see that the value indeed changed.</p>
<div style="padding-left: 1em; margin: 1em 0; position: relative;">
<div style="position: absolute; top: 0; bottom: 0%; left: 0; width: 3px; background-color: green;"></div>
<strong>Info</strong>: We will learn more in details about "getter" functions in the next example.
</div>
<!-- HTML_TAG_END -->
<div class="navMarkdown">
</div>
<a class="allExamples" href="all">All Examples</a></div></div>
<div class="splitter svelte-9dft0e">
<div class="splitter vertical svelte-7pb3g9" tabindex="0"><div class="line svelte-7pb3g9" style="--splitter-line-margin:NaNpx;--splitter-line-size:3px;--splitter-line-color:rgb(17, 17, 17);--splitter-line-hover-color:#444"></div>
</div>
</div>
<div class="secondary svelte-9dft0e">
<div class="split horizontal svelte-9dft0e" style="--primary-size:80%;--min-primary-size:0;--min-secondary-size:0;--splitter-size:7px"><div class="primary svelte-9dft0e"><div slot="primary" class="panelCode" style="position: absolute; top: 0; bottom: 0; left: 0; right: 0;"><div style="height: 100%; overflow: scroll;"><div contenteditable="false" class="dark"><pre>// this trait has to be imported
import "@stdlib/deploy";
// the Deployable trait adds a default receiver for the "Deploy" message
contract Counter with Deployable {
val: Int as uint32;
init() {
self.val = 0;
}
receive("increment") {
self.val = self.val + 1;
}
get fun value(): Int {
return self.val;
}
}</pre></div></div></div></div>
<div class="splitter svelte-9dft0e">
<div class="splitter horizontal svelte-7pb3g9" tabindex="0"><div class="line svelte-7pb3g9" style="--splitter-line-margin:NaNpx;--splitter-line-size:3px;--splitter-line-color:rgb(17, 17, 17);--splitter-line-hover-color:#444"></div>
</div>
</div>
<div class="secondary svelte-9dft0e"><div slot="secondary" class="panelBottom" style="position: absolute; top: 0; bottom: 0; left: 0; right: 0; display: flex; flex-direction: column;"><div style="display: flex; gap: 10px; flex-wrap: wrap; overflow: hidden;">
<button class="buttonAction svelteui-c-TfGwS svelteui-c-TfGwS-hQzioB-variation-filled svelteui-c-TfGwS-iPJLV-css svelte-1qnpzwq" tabindex="0">
Deploy
<div class="ripple svelte-1dillie"></div>
</button>
<button class="buttonAction svelteui-c-fAernD svelteui-c-fAernD-hkqluh-variation-filled svelteui-c-fAernD-iPJLV-css svelte-1qnpzwq" tabindex="0">
Get value
<div class="ripple svelte-1dillie"></div>
</button>
<button class="buttonAction svelteui-c-hYnOVn svelteui-c-hYnOVn-cKczaq-variation-filled svelteui-c-hYnOVn-iPJLV-css svelte-1qnpzwq" tabindex="0">
Send increment
<div class="ripple svelte-1dillie"></div>
</button></div>
<pre style="flex: 1; color: #666; overflow: scroll;"></pre></div></div>
</div>
</div>
</div>
<script>
{
__sveltekit_12rs9i2 = {
env: {},
base: new URL(".", location).pathname.slice(0, -1),
element: document.currentScript.parentElement
};
const data = [null,null,null];
Promise.all([
import("./_app/immutable/entry/start.b5438541.js"),
import("./_app/immutable/entry/app.06a021a8.js")
]).then(([kit, app]) => {
kit.start(app, __sveltekit_12rs9i2.element, {
node_ids: [0, 2, 7],
data,
form: null,
error: null
});
});
}
</script>
</div>
</body>
</html>