@goplausible/openclaw-algorand-plugin 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +112 -0
- package/index.ts +361 -0
- package/lib/mcp-servers.ts +14 -0
- package/lib/x402-fetch.ts +213 -0
- package/memory/algorand-plugin.md +82 -0
- package/openclaw.plugin.json +30 -0
- package/package.json +41 -0
- package/setup.ts +80 -0
- package/skills/algorand-development/SKILL.md +90 -0
- package/skills/algorand-development/references/build-smart-contracts-reference.md +79 -0
- package/skills/algorand-development/references/build-smart-contracts.md +52 -0
- package/skills/algorand-development/references/create-project-reference.md +86 -0
- package/skills/algorand-development/references/create-project.md +89 -0
- package/skills/algorand-development/references/implement-arc-standards-arc32-arc56.md +396 -0
- package/skills/algorand-development/references/implement-arc-standards-arc4.md +265 -0
- package/skills/algorand-development/references/implement-arc-standards.md +92 -0
- package/skills/algorand-development/references/search-algorand-examples-reference.md +119 -0
- package/skills/algorand-development/references/search-algorand-examples.md +89 -0
- package/skills/algorand-development/references/troubleshoot-errors-contract.md +373 -0
- package/skills/algorand-development/references/troubleshoot-errors-transaction.md +599 -0
- package/skills/algorand-development/references/troubleshoot-errors.md +105 -0
- package/skills/algorand-development/references/use-algokit-cli-reference.md +228 -0
- package/skills/algorand-development/references/use-algokit-cli.md +64 -0
- package/skills/algorand-interaction/SKILL.md +223 -0
- package/skills/algorand-interaction/references/algorand-mcp.md +743 -0
- package/skills/algorand-interaction/references/examples-algorand-mcp.md +647 -0
- package/skills/algorand-python/SKILL.md +95 -0
- package/skills/algorand-python/references/build-smart-contracts-decorators.md +413 -0
- package/skills/algorand-python/references/build-smart-contracts-reference.md +55 -0
- package/skills/algorand-python/references/build-smart-contracts-storage.md +452 -0
- package/skills/algorand-python/references/build-smart-contracts-transactions.md +445 -0
- package/skills/algorand-python/references/build-smart-contracts-types.md +438 -0
- package/skills/algorand-python/references/build-smart-contracts.md +82 -0
- package/skills/algorand-python/references/create-project-reference.md +55 -0
- package/skills/algorand-python/references/create-project.md +75 -0
- package/skills/algorand-python/references/implement-arc-standards-arc32-arc56.md +101 -0
- package/skills/algorand-python/references/implement-arc-standards-arc4.md +154 -0
- package/skills/algorand-python/references/implement-arc-standards.md +39 -0
- package/skills/algorand-python/references/troubleshoot-errors-contract.md +355 -0
- package/skills/algorand-python/references/troubleshoot-errors-transaction.md +430 -0
- package/skills/algorand-python/references/troubleshoot-errors.md +46 -0
- package/skills/algorand-python/references/use-algokit-utils-reference.md +350 -0
- package/skills/algorand-python/references/use-algokit-utils.md +76 -0
- package/skills/algorand-typescript/SKILL.md +131 -0
- package/skills/algorand-typescript/references/algorand-ts-migration-from-beta.md +448 -0
- package/skills/algorand-typescript/references/algorand-ts-migration-from-tealscript.md +487 -0
- package/skills/algorand-typescript/references/algorand-ts-migration.md +102 -0
- package/skills/algorand-typescript/references/algorand-typescript-syntax-methods-and-abi.md +134 -0
- package/skills/algorand-typescript/references/algorand-typescript-syntax-reference.md +58 -0
- package/skills/algorand-typescript/references/algorand-typescript-syntax-storage.md +154 -0
- package/skills/algorand-typescript/references/algorand-typescript-syntax-transactions.md +187 -0
- package/skills/algorand-typescript/references/algorand-typescript-syntax-types-and-values.md +150 -0
- package/skills/algorand-typescript/references/algorand-typescript-syntax.md +84 -0
- package/skills/algorand-typescript/references/build-smart-contracts-reference.md +52 -0
- package/skills/algorand-typescript/references/build-smart-contracts.md +74 -0
- package/skills/algorand-typescript/references/call-smart-contracts-reference.md +237 -0
- package/skills/algorand-typescript/references/call-smart-contracts.md +183 -0
- package/skills/algorand-typescript/references/create-project-reference.md +53 -0
- package/skills/algorand-typescript/references/create-project.md +86 -0
- package/skills/algorand-typescript/references/deploy-react-frontend-examples.md +527 -0
- package/skills/algorand-typescript/references/deploy-react-frontend-reference.md +412 -0
- package/skills/algorand-typescript/references/deploy-react-frontend.md +239 -0
- package/skills/algorand-typescript/references/implement-arc-standards-arc32-arc56.md +73 -0
- package/skills/algorand-typescript/references/implement-arc-standards-arc4.md +126 -0
- package/skills/algorand-typescript/references/implement-arc-standards.md +44 -0
- package/skills/algorand-typescript/references/test-smart-contracts-examples.md +245 -0
- package/skills/algorand-typescript/references/test-smart-contracts-unit-tests.md +147 -0
- package/skills/algorand-typescript/references/test-smart-contracts.md +127 -0
- package/skills/algorand-typescript/references/troubleshoot-errors-contract.md +296 -0
- package/skills/algorand-typescript/references/troubleshoot-errors-transaction.md +438 -0
- package/skills/algorand-typescript/references/troubleshoot-errors.md +56 -0
- package/skills/algorand-typescript/references/use-algokit-utils-reference.md +342 -0
- package/skills/algorand-typescript/references/use-algokit-utils.md +74 -0
- package/skills/algorand-x402-python/SKILL.md +113 -0
- package/skills/algorand-x402-python/references/create-python-x402-client-examples.md +469 -0
- package/skills/algorand-x402-python/references/create-python-x402-client-reference.md +313 -0
- package/skills/algorand-x402-python/references/create-python-x402-client.md +207 -0
- package/skills/algorand-x402-python/references/create-python-x402-facilitator-examples.md +924 -0
- package/skills/algorand-x402-python/references/create-python-x402-facilitator-reference.md +629 -0
- package/skills/algorand-x402-python/references/create-python-x402-facilitator.md +408 -0
- package/skills/algorand-x402-python/references/create-python-x402-server-examples.md +703 -0
- package/skills/algorand-x402-python/references/create-python-x402-server-reference.md +303 -0
- package/skills/algorand-x402-python/references/create-python-x402-server.md +221 -0
- package/skills/algorand-x402-python/references/explain-algorand-x402-python-examples.md +605 -0
- package/skills/algorand-x402-python/references/explain-algorand-x402-python-reference.md +315 -0
- package/skills/algorand-x402-python/references/explain-algorand-x402-python.md +167 -0
- package/skills/algorand-x402-python/references/use-python-x402-core-avm-examples.md +554 -0
- package/skills/algorand-x402-python/references/use-python-x402-core-avm-reference.md +278 -0
- package/skills/algorand-x402-python/references/use-python-x402-core-avm.md +166 -0
- package/skills/algorand-x402-typescript/SKILL.md +129 -0
- package/skills/algorand-x402-typescript/references/create-typescript-x402-client-examples.md +879 -0
- package/skills/algorand-x402-typescript/references/create-typescript-x402-client-reference.md +371 -0
- package/skills/algorand-x402-typescript/references/create-typescript-x402-client.md +236 -0
- package/skills/algorand-x402-typescript/references/create-typescript-x402-facilitator-examples.md +875 -0
- package/skills/algorand-x402-typescript/references/create-typescript-x402-facilitator-reference.md +461 -0
- package/skills/algorand-x402-typescript/references/create-typescript-x402-facilitator.md +270 -0
- package/skills/algorand-x402-typescript/references/create-typescript-x402-nextjs-examples.md +1181 -0
- package/skills/algorand-x402-typescript/references/create-typescript-x402-nextjs-reference.md +360 -0
- package/skills/algorand-x402-typescript/references/create-typescript-x402-nextjs.md +251 -0
- package/skills/algorand-x402-typescript/references/create-typescript-x402-paywall-examples.md +870 -0
- package/skills/algorand-x402-typescript/references/create-typescript-x402-paywall-reference.md +323 -0
- package/skills/algorand-x402-typescript/references/create-typescript-x402-paywall.md +281 -0
- package/skills/algorand-x402-typescript/references/create-typescript-x402-server-examples.md +1135 -0
- package/skills/algorand-x402-typescript/references/create-typescript-x402-server-reference.md +382 -0
- package/skills/algorand-x402-typescript/references/create-typescript-x402-server.md +216 -0
- package/skills/algorand-x402-typescript/references/explain-algorand-x402-typescript-examples.md +616 -0
- package/skills/algorand-x402-typescript/references/explain-algorand-x402-typescript-reference.md +323 -0
- package/skills/algorand-x402-typescript/references/explain-algorand-x402-typescript.md +232 -0
- package/skills/algorand-x402-typescript/references/use-typescript-x402-core-avm-examples.md +1417 -0
- package/skills/algorand-x402-typescript/references/use-typescript-x402-core-avm-reference.md +504 -0
- package/skills/algorand-x402-typescript/references/use-typescript-x402-core-avm.md +158 -0
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
# Algorand Python Types
|
|
2
|
+
|
|
3
|
+
Algorand Python provides statically-typed representations of AVM (Algorand Virtual Machine) types. These types differ from standard Python types and are essential for writing correct smart contracts.
|
|
4
|
+
|
|
5
|
+
## When to use this reference
|
|
6
|
+
|
|
7
|
+
Use this reference when:
|
|
8
|
+
|
|
9
|
+
- Writing Algorand Python smart contract code
|
|
10
|
+
- Encountering type errors in contract compilation
|
|
11
|
+
- Needing to understand differences between Python and AVM types
|
|
12
|
+
- Working with numbers, strings, or binary data in contracts
|
|
13
|
+
|
|
14
|
+
## Core AVM Types
|
|
15
|
+
|
|
16
|
+
### UInt64
|
|
17
|
+
|
|
18
|
+
`algopy.UInt64` represents a 64-bit unsigned integer—the primary numeric type on the AVM.
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
import algopy
|
|
22
|
+
|
|
23
|
+
# CORRECT - Initialize with integer literal
|
|
24
|
+
num = algopy.UInt64(1)
|
|
25
|
+
zero = algopy.UInt64() # Defaults to 0
|
|
26
|
+
|
|
27
|
+
# CORRECT - Arithmetic operations
|
|
28
|
+
total = num + 100
|
|
29
|
+
result = num * 2
|
|
30
|
+
divided = num // 3 # Must use floor division
|
|
31
|
+
|
|
32
|
+
# CORRECT - Boolean evaluation (zero is False)
|
|
33
|
+
if num:
|
|
34
|
+
algopy.log("Non-zero value")
|
|
35
|
+
|
|
36
|
+
# INCORRECT - Regular division not allowed
|
|
37
|
+
# bad = num / 2 # Error: Use // instead
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**Key differences from Python `int`:**
|
|
41
|
+
|
|
42
|
+
| Feature | Python `int` | `algopy.UInt64` |
|
|
43
|
+
|---------|--------------|-----------------|
|
|
44
|
+
| Range | Unbounded | 0 to 2^64-1 |
|
|
45
|
+
| Signed | Yes | No (unsigned only) |
|
|
46
|
+
| Division | `/` allowed | Must use `//` |
|
|
47
|
+
| Overflow | Never | Errors on overflow |
|
|
48
|
+
|
|
49
|
+
### Bytes
|
|
50
|
+
|
|
51
|
+
`algopy.Bytes` represents a byte sequence with a maximum length of 4096 bytes.
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
import algopy
|
|
55
|
+
|
|
56
|
+
# CORRECT - Initialize with bytes literal
|
|
57
|
+
data = algopy.Bytes(b"abc")
|
|
58
|
+
empty = algopy.Bytes() # Empty bytes
|
|
59
|
+
|
|
60
|
+
# CORRECT - Concatenation
|
|
61
|
+
combined = data + b"def" # b"abcdef"
|
|
62
|
+
|
|
63
|
+
# CORRECT - Indexing returns Bytes (not int!)
|
|
64
|
+
first = data[0] # Returns Bytes(b"a"), not 97
|
|
65
|
+
|
|
66
|
+
# CORRECT - Slicing
|
|
67
|
+
slice = data[:2] # Bytes(b"ab")
|
|
68
|
+
|
|
69
|
+
# CORRECT - Check containment
|
|
70
|
+
if b"ab" in data:
|
|
71
|
+
algopy.log("Found")
|
|
72
|
+
|
|
73
|
+
# CORRECT - Get length (not len()!)
|
|
74
|
+
length = data.length # UInt64(3)
|
|
75
|
+
|
|
76
|
+
# CORRECT - Construct from encodings
|
|
77
|
+
from_hex = algopy.Bytes.from_hex("FF")
|
|
78
|
+
from_base64 = algopy.Bytes.from_base64("RkY=")
|
|
79
|
+
from_base32 = algopy.Bytes.from_base32("74======")
|
|
80
|
+
|
|
81
|
+
# CORRECT - Binary operations
|
|
82
|
+
xor_result = data ^ b"xyz"
|
|
83
|
+
and_result = data & b"abc"
|
|
84
|
+
inverted = ~data
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**Key differences from Python `bytes`:**
|
|
88
|
+
|
|
89
|
+
| Feature | Python `bytes` | `algopy.Bytes` |
|
|
90
|
+
|---------|----------------|----------------|
|
|
91
|
+
| Max length | Memory limit | 4096 bytes |
|
|
92
|
+
| Indexing | Returns `int` | Returns `Bytes` |
|
|
93
|
+
| Length | `len(x)` | `x.length` |
|
|
94
|
+
|
|
95
|
+
### String
|
|
96
|
+
|
|
97
|
+
`algopy.String` represents a UTF-8 encoded string backed by `Bytes`.
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
import algopy
|
|
101
|
+
|
|
102
|
+
# CORRECT - Initialize with string literal
|
|
103
|
+
text = algopy.String("hello")
|
|
104
|
+
empty = algopy.String()
|
|
105
|
+
|
|
106
|
+
# CORRECT - Concatenation
|
|
107
|
+
greeting = text + " world"
|
|
108
|
+
|
|
109
|
+
# CORRECT - Boolean check (empty is False)
|
|
110
|
+
if text:
|
|
111
|
+
algopy.log("Has content")
|
|
112
|
+
|
|
113
|
+
# CORRECT - String operations
|
|
114
|
+
if text.startswith("he"):
|
|
115
|
+
algopy.log("Starts with 'he'")
|
|
116
|
+
|
|
117
|
+
if text.endswith("lo"):
|
|
118
|
+
algopy.log("Ends with 'lo'")
|
|
119
|
+
|
|
120
|
+
if "ell" in text:
|
|
121
|
+
algopy.log("Contains 'ell'")
|
|
122
|
+
|
|
123
|
+
# CORRECT - Join strings
|
|
124
|
+
result = algopy.String(", ").join((text, text)) # "hello, hello"
|
|
125
|
+
|
|
126
|
+
# CORRECT - Access underlying bytes
|
|
127
|
+
raw = text.bytes # Bytes(b"hello")
|
|
128
|
+
byte_length = text.bytes.length # UInt64(5)
|
|
129
|
+
|
|
130
|
+
# INCORRECT - No indexing or len()
|
|
131
|
+
# char = text[0] # Error: Not supported
|
|
132
|
+
# length = len(text) # Error: Use text.bytes.length
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
**String limitations:**
|
|
136
|
+
|
|
137
|
+
- No indexing (`text[0]`)
|
|
138
|
+
- No slicing (`text[1:3]`)
|
|
139
|
+
- No `len()` function (use `.bytes.length` for byte count)
|
|
140
|
+
- Expensive containment check (`in` operator)
|
|
141
|
+
|
|
142
|
+
### BigUInt
|
|
143
|
+
|
|
144
|
+
`algopy.BigUInt` represents a variable-length unsigned integer up to 512 bits.
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
import algopy
|
|
148
|
+
|
|
149
|
+
# CORRECT - Initialize with integer or UInt64
|
|
150
|
+
big = algopy.BigUInt(12345678901234567890)
|
|
151
|
+
from_uint = algopy.BigUInt(algopy.UInt64(100))
|
|
152
|
+
|
|
153
|
+
# CORRECT - Arithmetic (same as UInt64)
|
|
154
|
+
result = big + 1000
|
|
155
|
+
divided = big // 10
|
|
156
|
+
|
|
157
|
+
# INCORRECT - No power or shift operators
|
|
158
|
+
# bad = big ** 2 # Error: Not supported
|
|
159
|
+
# bad = big << 2 # Error: Not supported
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
**When to use BigUInt:**
|
|
163
|
+
|
|
164
|
+
- Numbers exceeding 2^64-1
|
|
165
|
+
- Cryptographic operations requiring large integers
|
|
166
|
+
- High-precision financial calculations
|
|
167
|
+
|
|
168
|
+
**Cost consideration:** BigUInt operations are ~10x more expensive than UInt64 operations. Use `algopy.op` wide operations (`addw`, `mulw`) for overflow handling when possible.
|
|
169
|
+
|
|
170
|
+
## Reference Types
|
|
171
|
+
|
|
172
|
+
Reference types represent on-chain entities and require "resource availability" to access their properties.
|
|
173
|
+
|
|
174
|
+
### Account
|
|
175
|
+
|
|
176
|
+
`algopy.Account` represents an Algorand address.
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
import algopy
|
|
180
|
+
|
|
181
|
+
# CORRECT - Initialize with address string
|
|
182
|
+
account = algopy.Account("WMHF4FLJNKY2BPFK7YPV5ID6OZ7LVDB2B66ZTXEAMLL2NX4WJZRJFVX66M")
|
|
183
|
+
|
|
184
|
+
# CORRECT - Initialize from bytes (32 bytes)
|
|
185
|
+
from_bytes = algopy.Account(some_32_bytes)
|
|
186
|
+
|
|
187
|
+
# Zero address (default)
|
|
188
|
+
zero_addr = algopy.Account()
|
|
189
|
+
|
|
190
|
+
# CORRECT - Boolean check (False if zero-address)
|
|
191
|
+
if account:
|
|
192
|
+
algopy.log("Valid address")
|
|
193
|
+
|
|
194
|
+
# CORRECT - Access properties (requires resource availability)
|
|
195
|
+
balance = account.balance # UInt64 in microAlgos
|
|
196
|
+
min_bal = account.min_balance
|
|
197
|
+
auth = account.auth_address # Rekeyed address
|
|
198
|
+
|
|
199
|
+
# CORRECT - Check opt-in status
|
|
200
|
+
asset = algopy.Asset(1234)
|
|
201
|
+
if account.is_opted_in(asset):
|
|
202
|
+
algopy.log("Opted into asset")
|
|
203
|
+
|
|
204
|
+
app = algopy.Application(5678)
|
|
205
|
+
if account.is_opted_in(app):
|
|
206
|
+
algopy.log("Opted into app")
|
|
207
|
+
|
|
208
|
+
# CORRECT - Get raw bytes
|
|
209
|
+
raw = account.bytes # 32 bytes
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
**Account properties (require resource availability):**
|
|
213
|
+
|
|
214
|
+
| Property | Type | Description |
|
|
215
|
+
|----------|------|-------------|
|
|
216
|
+
| `balance` | `UInt64` | Balance in microAlgos |
|
|
217
|
+
| `min_balance` | `UInt64` | Minimum required balance |
|
|
218
|
+
| `auth_address` | `Account` | Rekeyed-to address |
|
|
219
|
+
| `total_apps_created` | `UInt64` | Apps created by account |
|
|
220
|
+
| `total_apps_opted_in` | `UInt64` | Apps account opted into |
|
|
221
|
+
| `total_assets_created` | `UInt64` | Assets created |
|
|
222
|
+
| `total_extra_app_pages` | `UInt64` | Extra app pages |
|
|
223
|
+
| `bytes` | `Bytes` | Raw 32-byte address |
|
|
224
|
+
|
|
225
|
+
### Asset
|
|
226
|
+
|
|
227
|
+
`algopy.Asset` represents an Algorand Standard Asset (ASA).
|
|
228
|
+
|
|
229
|
+
```python
|
|
230
|
+
import algopy
|
|
231
|
+
|
|
232
|
+
# CORRECT - Initialize with asset ID
|
|
233
|
+
asset = algopy.Asset(1234)
|
|
234
|
+
invalid = algopy.Asset() # ID 0 (invalid)
|
|
235
|
+
|
|
236
|
+
# CORRECT - Boolean check (False if ID is 0)
|
|
237
|
+
if asset:
|
|
238
|
+
algopy.log("Valid asset")
|
|
239
|
+
|
|
240
|
+
# CORRECT - Access properties (requires resource availability)
|
|
241
|
+
name = asset.name # Bytes
|
|
242
|
+
unit = asset.unit_name # Bytes
|
|
243
|
+
total = asset.total # UInt64
|
|
244
|
+
decimals = asset.decimals # UInt64
|
|
245
|
+
creator = asset.creator # Account
|
|
246
|
+
manager = asset.manager # Account
|
|
247
|
+
|
|
248
|
+
# CORRECT - Get balance for an account
|
|
249
|
+
account = algopy.Account("...")
|
|
250
|
+
balance = asset.balance(account)
|
|
251
|
+
|
|
252
|
+
# CORRECT - Check frozen status
|
|
253
|
+
is_frozen = asset.frozen(account)
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
**Asset properties (require resource availability):**
|
|
257
|
+
|
|
258
|
+
| Property | Type | Description |
|
|
259
|
+
|----------|------|-------------|
|
|
260
|
+
| `id` | `UInt64` | Asset ID |
|
|
261
|
+
| `name` | `Bytes` | Asset name |
|
|
262
|
+
| `unit_name` | `Bytes` | Unit name (ticker) |
|
|
263
|
+
| `total` | `UInt64` | Total supply |
|
|
264
|
+
| `decimals` | `UInt64` | Decimal places |
|
|
265
|
+
| `creator` | `Account` | Creator address |
|
|
266
|
+
| `manager` | `Account` | Manager address |
|
|
267
|
+
| `reserve` | `Account` | Reserve address |
|
|
268
|
+
| `freeze` | `Account` | Freeze address |
|
|
269
|
+
| `clawback` | `Account` | Clawback address |
|
|
270
|
+
| `default_frozen` | `bool` | Default frozen state |
|
|
271
|
+
| `url` | `Bytes` | Asset URL |
|
|
272
|
+
| `metadata_hash` | `Bytes` | 32-byte hash |
|
|
273
|
+
|
|
274
|
+
### Application
|
|
275
|
+
|
|
276
|
+
`algopy.Application` represents a smart contract application.
|
|
277
|
+
|
|
278
|
+
```python
|
|
279
|
+
import algopy
|
|
280
|
+
|
|
281
|
+
# CORRECT - Initialize with app ID
|
|
282
|
+
app = algopy.Application(5678)
|
|
283
|
+
invalid = algopy.Application() # ID 0 (invalid)
|
|
284
|
+
|
|
285
|
+
# CORRECT - Boolean check
|
|
286
|
+
if app:
|
|
287
|
+
algopy.log("Valid app")
|
|
288
|
+
|
|
289
|
+
# CORRECT - Access properties (requires resource availability)
|
|
290
|
+
creator = app.creator # Account
|
|
291
|
+
address = app.address # Account (app's address)
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
## Python Built-in Types
|
|
295
|
+
|
|
296
|
+
Standard Python types have limited support in Algorand Python.
|
|
297
|
+
|
|
298
|
+
### Supported
|
|
299
|
+
|
|
300
|
+
| Type | Usage |
|
|
301
|
+
|------|-------|
|
|
302
|
+
| `bool` | Full support |
|
|
303
|
+
| `tuple` | Arguments, return types, local variables |
|
|
304
|
+
| `typing.NamedTuple` | Structured data |
|
|
305
|
+
| `None` | Return type annotation only |
|
|
306
|
+
|
|
307
|
+
### Limited Support
|
|
308
|
+
|
|
309
|
+
```python
|
|
310
|
+
# Module-level constants only
|
|
311
|
+
MY_CONSTANT: int = 42
|
|
312
|
+
MY_STRING: str = "hello"
|
|
313
|
+
MY_BYTES: bytes = b"data"
|
|
314
|
+
|
|
315
|
+
# CORRECT - Use with AVM types
|
|
316
|
+
num = algopy.UInt64(MY_CONSTANT)
|
|
317
|
+
text = algopy.String(MY_STRING)
|
|
318
|
+
data = algopy.Bytes(MY_BYTES)
|
|
319
|
+
|
|
320
|
+
# INCORRECT - Cannot use as local variables
|
|
321
|
+
# def my_method(self) -> None:
|
|
322
|
+
# x: int = 5 # Error: Use UInt64
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### Not Supported
|
|
326
|
+
|
|
327
|
+
- `float` — No floating-point on AVM
|
|
328
|
+
- Nested tuples
|
|
329
|
+
- `None` as a value (only as type annotation)
|
|
330
|
+
|
|
331
|
+
## ARC-4 Types
|
|
332
|
+
|
|
333
|
+
ARC-4 types provide ABI-compatible encoding. Import from `algopy.arc4`.
|
|
334
|
+
|
|
335
|
+
```python
|
|
336
|
+
from algopy import arc4
|
|
337
|
+
|
|
338
|
+
# ARC-4 integers (big-endian encoded)
|
|
339
|
+
uint8 = arc4.UInt8(255)
|
|
340
|
+
uint64 = arc4.UInt64(12345)
|
|
341
|
+
uint256 = arc4.BigUIntN[typing.Literal[256]](...)
|
|
342
|
+
|
|
343
|
+
# ARC-4 strings (length-prefixed)
|
|
344
|
+
arc4_str = arc4.String("hello")
|
|
345
|
+
native_str = arc4_str.native # Convert to algopy.String
|
|
346
|
+
|
|
347
|
+
# ARC-4 dynamic bytes
|
|
348
|
+
dyn_bytes = arc4.DynamicBytes(b"data")
|
|
349
|
+
|
|
350
|
+
# ARC-4 address (32 bytes)
|
|
351
|
+
address = arc4.Address("WMHF4...")
|
|
352
|
+
native_account = address.native # Convert to algopy.Account
|
|
353
|
+
|
|
354
|
+
# ARC-4 arrays
|
|
355
|
+
static_arr = arc4.StaticArray[arc4.UInt8, typing.Literal[4]](...)
|
|
356
|
+
dynamic_arr = arc4.DynamicArray[arc4.UInt64](...)
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
**When to use ARC-4 types:**
|
|
360
|
+
|
|
361
|
+
- ABI method parameters and return values
|
|
362
|
+
- Structured data in boxes or state
|
|
363
|
+
- Interoperability with other contracts/clients
|
|
364
|
+
|
|
365
|
+
**Conversion to native types:**
|
|
366
|
+
|
|
367
|
+
```python
|
|
368
|
+
# Use .native property to convert
|
|
369
|
+
arc4_value = arc4.UInt64(100)
|
|
370
|
+
native_value = arc4_value.native # algopy.UInt64
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
## Common Mistakes
|
|
374
|
+
|
|
375
|
+
### Using Python `int` instead of `UInt64`
|
|
376
|
+
|
|
377
|
+
```python
|
|
378
|
+
# INCORRECT
|
|
379
|
+
def bad_method(self) -> int:
|
|
380
|
+
x = 5 # Python int not allowed
|
|
381
|
+
return x
|
|
382
|
+
|
|
383
|
+
# CORRECT
|
|
384
|
+
def good_method(self) -> algopy.UInt64:
|
|
385
|
+
x = algopy.UInt64(5)
|
|
386
|
+
return x
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
### Using `len()` instead of `.length`
|
|
390
|
+
|
|
391
|
+
```python
|
|
392
|
+
# INCORRECT
|
|
393
|
+
data = algopy.Bytes(b"hello")
|
|
394
|
+
# length = len(data) # Error: len() not supported
|
|
395
|
+
|
|
396
|
+
# CORRECT
|
|
397
|
+
length = data.length # UInt64(5)
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
### Using `/` instead of `//`
|
|
401
|
+
|
|
402
|
+
```python
|
|
403
|
+
# INCORRECT
|
|
404
|
+
# result = algopy.UInt64(10) / 2 # Error
|
|
405
|
+
|
|
406
|
+
# CORRECT
|
|
407
|
+
result = algopy.UInt64(10) // 2 # UInt64(5)
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
### Forgetting resource availability
|
|
411
|
+
|
|
412
|
+
```python
|
|
413
|
+
# Properties require the Account/Asset/Application to be
|
|
414
|
+
# in the transaction's reference arrays
|
|
415
|
+
|
|
416
|
+
def check_balance(self, account: algopy.Account) -> algopy.UInt64:
|
|
417
|
+
# This only works if 'account' is in the accounts array
|
|
418
|
+
return account.balance
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
## Type Comparison Table
|
|
422
|
+
|
|
423
|
+
| Concept | Python | Algorand Python |
|
|
424
|
+
|---------|--------|-----------------|
|
|
425
|
+
| Integer | `int` | `UInt64`, `BigUInt` |
|
|
426
|
+
| Bytes | `bytes` | `Bytes` |
|
|
427
|
+
| String | `str` | `String` |
|
|
428
|
+
| Division | `x / y` | `x // y` |
|
|
429
|
+
| Length | `len(x)` | `x.length` |
|
|
430
|
+
| Iteration | `range()` | `urange()` |
|
|
431
|
+
| Enumerate | `enumerate()` | `uenumerate()` |
|
|
432
|
+
|
|
433
|
+
## References
|
|
434
|
+
|
|
435
|
+
- [Algorand Python Types Documentation](https://dev.algorand.co/algokit/languages/python/lg-types/)
|
|
436
|
+
- [ARC-4 Types](https://dev.algorand.co/algokit/languages/python/lg-arc4/)
|
|
437
|
+
- [Python Builtins](https://dev.algorand.co/algokit/languages/python/lg-builtins/)
|
|
438
|
+
- [algopy API Reference](https://dev.algorand.co/reference/algorand-python/api/api-algopy/)
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Building Smart Contracts (Python)
|
|
2
|
+
|
|
3
|
+
Create Algorand smart contracts using Algorand Python (PuyaPy) -- a statically-typed Python subset compiled to TEAL bytecode by the Puya compiler.
|
|
4
|
+
|
|
5
|
+
## Core Workflow
|
|
6
|
+
|
|
7
|
+
1. **Search documentation** for concepts and best practices
|
|
8
|
+
2. **Retrieve canonical Python examples** from priority repositories
|
|
9
|
+
3. **Generate code** following Algorand Python syntax rules
|
|
10
|
+
4. **Include integration tests** using generated clients
|
|
11
|
+
5. **Build and test** with AlgoKit commands
|
|
12
|
+
|
|
13
|
+
## Python Repository Priorities
|
|
14
|
+
|
|
15
|
+
When retrieving examples, search these repositories in order:
|
|
16
|
+
|
|
17
|
+
1. **`algorandfoundation/devportal-code-examples`**
|
|
18
|
+
- Path: `projects/python-examples/contracts/`
|
|
19
|
+
- Best source for common patterns (state management, ABI methods, etc.)
|
|
20
|
+
- Always include corresponding test files
|
|
21
|
+
|
|
22
|
+
2. **`algorandfoundation/puya`**
|
|
23
|
+
- Path: `examples/`
|
|
24
|
+
- Examples: `hello_world_arc4/`, `voting/`, `amm/`
|
|
25
|
+
- Best for compiler-level patterns and advanced features (BoxMap, inner transactions)
|
|
26
|
+
|
|
27
|
+
3. **`algorandfoundation/algokit-python-template`**
|
|
28
|
+
- Project scaffolding and structure reference
|
|
29
|
+
- Integration test patterns
|
|
30
|
+
|
|
31
|
+
## Python-Specific Patterns
|
|
32
|
+
|
|
33
|
+
### Contract Base Class
|
|
34
|
+
Use `ARC4Contract` for contracts that expose ABI methods:
|
|
35
|
+
```python
|
|
36
|
+
from algopy import ARC4Contract, arc4
|
|
37
|
+
|
|
38
|
+
class MyContract(ARC4Contract):
|
|
39
|
+
@arc4.abimethod
|
|
40
|
+
def hello(self, name: arc4.String) -> arc4.String:
|
|
41
|
+
return "Hello, " + name
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Key Syntax Rules
|
|
45
|
+
|
|
46
|
+
- Contracts extend `ARC4Contract` from `algopy`
|
|
47
|
+
- Use `@arc4.abimethod` decorator for ABI-callable methods
|
|
48
|
+
- Use `@arc4.baremethod` for bare methods (no ABI selector, no args)
|
|
49
|
+
- Use `@subroutine` for internal reusable functions
|
|
50
|
+
- Use `GlobalState`, `LocalState`, `Box`, `BoxMap`, `BoxRef` for storage
|
|
51
|
+
- Use `itxn` namespace for inner transactions
|
|
52
|
+
- Always set `fee=0` on inner transactions (fee pooling)
|
|
53
|
+
- Use ARC-4 types (`arc4.UInt64`, `arc4.String`) for ABI method signatures
|
|
54
|
+
- Use native types (`UInt64`, `String`) for internal logic
|
|
55
|
+
|
|
56
|
+
## Python-Specific Deep-Dive References
|
|
57
|
+
|
|
58
|
+
For detailed Python syntax patterns, consult these references:
|
|
59
|
+
|
|
60
|
+
- [Decorators](./build-smart-contracts-decorators.md) -- `@arc4.abimethod`, `@arc4.baremethod`, `@subroutine`, lifecycle methods
|
|
61
|
+
- [Storage](./build-smart-contracts-storage.md) -- GlobalState, LocalState, Box, BoxMap, BoxRef, MBR costs
|
|
62
|
+
- [Transactions](./build-smart-contracts-transactions.md) -- Inner transactions, group transactions, fee pooling
|
|
63
|
+
- [Types](./build-smart-contracts-types.md) -- AVM types (`UInt64`, `Bytes`, `String`), ARC-4 types, reference types
|
|
64
|
+
|
|
65
|
+
## Build and Test
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
algokit project run build # Compile contracts
|
|
69
|
+
algokit project run test # Run tests
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Important Rules
|
|
73
|
+
|
|
74
|
+
- **NEVER use PyTEAL or Beaker** -- these are legacy, superseded by Puya
|
|
75
|
+
- **NEVER write raw TEAL** -- always use Algorand Python
|
|
76
|
+
- **NEVER import external libraries** into contract code
|
|
77
|
+
- **Always search docs first** before writing code
|
|
78
|
+
- **Always retrieve Python examples** from priority repositories
|
|
79
|
+
|
|
80
|
+
## References
|
|
81
|
+
|
|
82
|
+
- [Python Repository and Pattern Reference](./build-smart-contracts-reference.md)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# AlgoKit Init CLI Reference (Python)
|
|
2
|
+
|
|
3
|
+
## Python Presets
|
|
4
|
+
|
|
5
|
+
| Preset | Description |
|
|
6
|
+
| ------------ | ------------------------------------ |
|
|
7
|
+
| `Starter` | Simple starting point |
|
|
8
|
+
| `Production` | Tests, CI/CD, linting, type checking |
|
|
9
|
+
|
|
10
|
+
## Command Patterns
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
# Python (Production preset)
|
|
14
|
+
algokit init -n <name> -t python --answer preset_name production --answer author_name "<author>" --defaults
|
|
15
|
+
|
|
16
|
+
# Python (Starter preset)
|
|
17
|
+
algokit init -n <name> -t python --answer author_name "<author>" --defaults
|
|
18
|
+
|
|
19
|
+
# Python with TypeScript deployment scripts
|
|
20
|
+
algokit init -n <name> -t python --answer deployment_language "typescript" --defaults
|
|
21
|
+
|
|
22
|
+
# Skip git and bootstrap
|
|
23
|
+
algokit init -n <name> -t python --no-git --no-bootstrap --defaults
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Options
|
|
27
|
+
|
|
28
|
+
| Flag | Description |
|
|
29
|
+
| ---------------------------- | ------------------------------------------------ |
|
|
30
|
+
| `-n, --name <name>` | Project directory name (required) |
|
|
31
|
+
| `-t, --template python` | Python template (required) |
|
|
32
|
+
| `--answer "<key>" "<value>"` | Answer template prompts |
|
|
33
|
+
| `--defaults` | Accept all defaults |
|
|
34
|
+
| `--no-git` | Skip git initialization |
|
|
35
|
+
| `--no-bootstrap` | Skip dependency installation |
|
|
36
|
+
| `--workspace` | Create within workspace structure (default) |
|
|
37
|
+
| `--no-workspace` | Create standalone project |
|
|
38
|
+
|
|
39
|
+
## Deployment Language Option
|
|
40
|
+
|
|
41
|
+
Python projects support an optional `deployment_language` answer to control what language is used for deployment scripts:
|
|
42
|
+
|
|
43
|
+
| Value | Description |
|
|
44
|
+
| ------------ | ------------------------------------------ |
|
|
45
|
+
| `python` | Python deployment scripts (default) |
|
|
46
|
+
| `typescript` | TypeScript deployment scripts |
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
algokit init -n <name> -t python --answer deployment_language "typescript" --defaults
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Full Reference
|
|
53
|
+
|
|
54
|
+
- [AlgoKit Init Command](https://dev.algorand.co/reference/algokit-cli/#init)
|
|
55
|
+
- [AlgoKit Templates](https://dev.algorand.co/algokit/official-algokit-templates/)
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# AlgoKit Project Initialization (Python)
|
|
2
|
+
|
|
3
|
+
Create new Algorand Python projects using AlgoKit's official templates.
|
|
4
|
+
|
|
5
|
+
## Overview / Core Workflow
|
|
6
|
+
|
|
7
|
+
1. Confirm project details with user (name, preset, customizations)
|
|
8
|
+
2. Run `algokit init` with the Python template
|
|
9
|
+
3. Handle any initialization errors
|
|
10
|
+
4. Provide next steps for building/testing
|
|
11
|
+
|
|
12
|
+
## How to Proceed
|
|
13
|
+
|
|
14
|
+
1. **Confirm project details with user:**
|
|
15
|
+
- Project name (directory name)
|
|
16
|
+
- Preset choice (Production or Starter)
|
|
17
|
+
- Any customizations (`--no-git`, `--no-bootstrap`, author name)
|
|
18
|
+
- Deployment language preference (Python or TypeScript)
|
|
19
|
+
|
|
20
|
+
2. **Run initialization command:**
|
|
21
|
+
|
|
22
|
+
**Python (Production Preset):**
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
algokit init -n <project-name> -t python --answer preset_name production --answer author_name "<name>" --defaults
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**Python (Starter Preset):**
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
algokit init -n <project-name> -t python --answer author_name "<name>" --defaults
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Python with TypeScript deployment scripts:**
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
algokit init -n <project-name> -t python --answer deployment_language "typescript" --defaults
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
3. **Handle errors:**
|
|
41
|
+
- Check if project directory already exists
|
|
42
|
+
- Verify AlgoKit is installed: `algokit --version`
|
|
43
|
+
- Ensure target directory is writable
|
|
44
|
+
|
|
45
|
+
4. **Provide next steps:**
|
|
46
|
+
- `cd <project-name>`
|
|
47
|
+
- `algokit project run build` -- Compile contracts
|
|
48
|
+
- `algokit project run test` -- Run test suite
|
|
49
|
+
- `algokit localnet start` -- Start local network (if deploying)
|
|
50
|
+
- `algokit project run deploy` -- Deploy contracts to local network
|
|
51
|
+
|
|
52
|
+
## Python-Specific Customizations
|
|
53
|
+
|
|
54
|
+
| Customization | Command |
|
|
55
|
+
|---------------|---------|
|
|
56
|
+
| Set author name | `--answer author_name "Your Name"` |
|
|
57
|
+
| Production preset | `--answer preset_name production` |
|
|
58
|
+
| Starter preset | Omit `preset_name` (default) |
|
|
59
|
+
| TypeScript deployment scripts | `--answer deployment_language "typescript"` |
|
|
60
|
+
| Skip git init | `--no-git` |
|
|
61
|
+
| Skip dependency install | `--no-bootstrap` |
|
|
62
|
+
|
|
63
|
+
## Important Rules / Guidelines
|
|
64
|
+
|
|
65
|
+
- **Always confirm with user before executing** -- Never run `algokit init` without explicit confirmation
|
|
66
|
+
- **Use production preset** -- For any serious project because it includes testing framework and deployment scripts
|
|
67
|
+
- **Include author name** -- Pass `--answer author_name "<name>"` for attribution
|
|
68
|
+
- **Use `--defaults`** -- Accepts all other default values for non-interactive mode
|
|
69
|
+
- **Deployment language** -- Python projects can optionally use TypeScript for deployment scripts via `--answer deployment_language "typescript"`
|
|
70
|
+
|
|
71
|
+
## References / Further Reading
|
|
72
|
+
|
|
73
|
+
- [CLI Reference](./create-project-reference.md)
|
|
74
|
+
- [AlgoKit CLI Init Documentation](https://dev.algorand.co/algokit/cli/init/)
|
|
75
|
+
- [AlgoKit CLI Init Reference](https://dev.algorand.co/reference/algokit-cli#init)
|