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 +38 -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,265 @@
|
|
|
1
|
+
# ARC-4: Application Binary Interface
|
|
2
|
+
|
|
3
|
+
ARC-4 defines how to encode method calls, arguments, and return values for Algorand smart contracts. It enables interoperability between contracts, clients, wallets, and explorers.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [ARC-4 Types](#arc-4-types)
|
|
8
|
+
- [Primitive Types](#primitive-types)
|
|
9
|
+
- [Complex Types](#complex-types)
|
|
10
|
+
- [Reference Types](#reference-types-arguments-only)
|
|
11
|
+
- [Transaction Types](#transaction-types-arguments-only)
|
|
12
|
+
- [Using ARC-4 Types](#using-arc-4-types)
|
|
13
|
+
- [Method Signatures and Selectors](#method-signatures-and-selectors)
|
|
14
|
+
- [Encoding Rules](#encoding-rules)
|
|
15
|
+
- [Static vs Dynamic Types](#static-vs-dynamic-types)
|
|
16
|
+
- [Tuple Encoding](#tuple-encoding-head--tail)
|
|
17
|
+
- [Boolean Packing](#boolean-packing)
|
|
18
|
+
- [Method Invocation](#method-invocation)
|
|
19
|
+
- [Common Mistakes](#common-mistakes)
|
|
20
|
+
|
|
21
|
+
## ARC-4 Types
|
|
22
|
+
|
|
23
|
+
### Primitive Types
|
|
24
|
+
|
|
25
|
+
| Type | Description | Encoding |
|
|
26
|
+
|------|-------------|----------|
|
|
27
|
+
| `uint<N>` | N-bit unsigned integer (8-512, N%8=0) | Big-endian N bits |
|
|
28
|
+
| `byte` | Alias for `uint8` | 1 byte |
|
|
29
|
+
| `bool` | Boolean (0 or 1) | MSB of 1 byte; consecutive bools are packed |
|
|
30
|
+
| `ufixed<N>x<M>` | Fixed-point decimal | N bits, value = encoded / 10^M |
|
|
31
|
+
|
|
32
|
+
### Complex Types
|
|
33
|
+
|
|
34
|
+
| Type | Description | Encoding |
|
|
35
|
+
|------|-------------|----------|
|
|
36
|
+
| `address` | 32-byte Algorand address | Equivalent to `byte[32]` |
|
|
37
|
+
| `string` | UTF-8 encoded text | 2-byte length prefix + bytes |
|
|
38
|
+
| `<type>[N]` | Fixed-length array | N elements packed together |
|
|
39
|
+
| `<type>[]` | Variable-length array | 2-byte length prefix + elements |
|
|
40
|
+
| `(T1,T2,...,TN)` | Tuple | Head (offsets) + Tail (dynamic data) |
|
|
41
|
+
|
|
42
|
+
### Reference Types (Arguments Only)
|
|
43
|
+
|
|
44
|
+
| Type | Description | Encoded As |
|
|
45
|
+
|------|-------------|------------|
|
|
46
|
+
| `account` | Algorand account | `uint8` index into Accounts array |
|
|
47
|
+
| `asset` | Algorand Standard Asset | `uint8` index into Foreign Assets array |
|
|
48
|
+
| `application` | Algorand Application | `uint8` index into Foreign Apps array |
|
|
49
|
+
|
|
50
|
+
**Important:** Reference types cannot be used as return types.
|
|
51
|
+
|
|
52
|
+
### Transaction Types (Arguments Only)
|
|
53
|
+
|
|
54
|
+
| Type | Description |
|
|
55
|
+
|------|-------------|
|
|
56
|
+
| `txn` | Any transaction |
|
|
57
|
+
| `pay` | Payment transaction |
|
|
58
|
+
| `axfer` | Asset transfer transaction |
|
|
59
|
+
| `acfg` | Asset config transaction |
|
|
60
|
+
| `afrz` | Asset freeze transaction |
|
|
61
|
+
| `appl` | Application call transaction |
|
|
62
|
+
| `keyreg` | Key registration transaction |
|
|
63
|
+
|
|
64
|
+
Transaction arguments are encoded as preceding transactions in the group, not in ApplicationArgs.
|
|
65
|
+
|
|
66
|
+
## Using ARC-4 Types
|
|
67
|
+
|
|
68
|
+
### Python (Algorand Python)
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from algopy import ARC4Contract, arc4, Account, Asset, Application
|
|
72
|
+
|
|
73
|
+
class MyContract(ARC4Contract):
|
|
74
|
+
@arc4.abimethod
|
|
75
|
+
def demo_types(
|
|
76
|
+
self,
|
|
77
|
+
# Primitive types
|
|
78
|
+
amount: arc4.UInt64,
|
|
79
|
+
flag: arc4.Bool,
|
|
80
|
+
name: arc4.String,
|
|
81
|
+
|
|
82
|
+
# Reference types (automatically handled)
|
|
83
|
+
user: Account, # Passed as Account, encoded as uint8 index
|
|
84
|
+
token: Asset, # Passed as Asset, encoded as uint8 index
|
|
85
|
+
app: Application, # Passed as Application, encoded as uint8 index
|
|
86
|
+
|
|
87
|
+
# Complex types
|
|
88
|
+
data: arc4.DynamicBytes,
|
|
89
|
+
addr: arc4.Address,
|
|
90
|
+
) -> arc4.String:
|
|
91
|
+
return arc4.String("Success")
|
|
92
|
+
|
|
93
|
+
@arc4.abimethod
|
|
94
|
+
def with_transaction(
|
|
95
|
+
self,
|
|
96
|
+
payment: gtxn.PaymentTransaction, # Preceding payment in group
|
|
97
|
+
amount: arc4.UInt64,
|
|
98
|
+
) -> None:
|
|
99
|
+
assert payment.receiver == Global.current_application_address
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### TypeScript (Algorand TypeScript)
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import { Contract, Account, Asset, Application, Global } from '@algorandfoundation/algorand-typescript'
|
|
106
|
+
import { abimethod, UInt64, Bool, Str, DynamicBytes, Address } from '@algorandfoundation/algorand-typescript/arc4'
|
|
107
|
+
import { PaymentTxn } from '@algorandfoundation/algorand-typescript/gtxn'
|
|
108
|
+
|
|
109
|
+
class MyContract extends Contract {
|
|
110
|
+
@abimethod()
|
|
111
|
+
demoTypes(
|
|
112
|
+
// Primitive types
|
|
113
|
+
amount: UInt64,
|
|
114
|
+
flag: Bool,
|
|
115
|
+
name: Str,
|
|
116
|
+
|
|
117
|
+
// Reference types
|
|
118
|
+
user: Account,
|
|
119
|
+
token: Asset,
|
|
120
|
+
app: Application,
|
|
121
|
+
|
|
122
|
+
// Complex types
|
|
123
|
+
data: DynamicBytes,
|
|
124
|
+
addr: Address,
|
|
125
|
+
): Str {
|
|
126
|
+
return new Str('Success')
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
@abimethod()
|
|
130
|
+
withTransaction(
|
|
131
|
+
payment: PaymentTxn, // Preceding payment in group
|
|
132
|
+
amount: UInt64,
|
|
133
|
+
): void {
|
|
134
|
+
assert(payment.receiver === Global.currentApplicationAddress)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Method Signatures and Selectors
|
|
140
|
+
|
|
141
|
+
### Signature Format
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
method_name(arg1_type,arg2_type,...)return_type
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
- No spaces
|
|
148
|
+
- No argument names
|
|
149
|
+
- `void` for no return value
|
|
150
|
+
|
|
151
|
+
### Examples
|
|
152
|
+
|
|
153
|
+
| Method | Signature |
|
|
154
|
+
|--------|-----------|
|
|
155
|
+
| `def add(a: UInt64, b: UInt64) -> UInt128` | `add(uint64,uint64)uint128` |
|
|
156
|
+
| `def greet(name: String) -> String` | `greet(string)string` |
|
|
157
|
+
| `def transfer(to: Account, amt: UInt64) -> None` | `transfer(account,uint64)void` |
|
|
158
|
+
| `def process(p: PaymentTxn, d: Bytes) -> None` | `process(pay,byte[])void` |
|
|
159
|
+
|
|
160
|
+
### Selector Calculation
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
import hashlib
|
|
164
|
+
|
|
165
|
+
def get_selector(signature: str) -> bytes:
|
|
166
|
+
"""Calculate ARC-4 method selector."""
|
|
167
|
+
hash_bytes = hashlib.sha512_256(signature.encode()).digest()
|
|
168
|
+
return hash_bytes[:4]
|
|
169
|
+
|
|
170
|
+
# Example
|
|
171
|
+
selector = get_selector("add(uint64,uint64)uint128")
|
|
172
|
+
# Returns: b'\x8a\xa3\xb6\x1f' (hex: 8aa3b61f)
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Encoding Rules
|
|
176
|
+
|
|
177
|
+
### Static vs Dynamic Types
|
|
178
|
+
|
|
179
|
+
**Static types** have fixed size:
|
|
180
|
+
- `uint<N>`, `byte`, `bool`, `ufixed<N>x<M>`
|
|
181
|
+
- `address` (always 32 bytes)
|
|
182
|
+
- `<type>[N]` where `type` is static
|
|
183
|
+
- `(T1,...,TN)` where all Ti are static
|
|
184
|
+
|
|
185
|
+
**Dynamic types** have variable size:
|
|
186
|
+
- `string`, `<type>[]`
|
|
187
|
+
- `<type>[N]` where `type` is dynamic
|
|
188
|
+
- `(T1,...,TN)` where any Ti is dynamic
|
|
189
|
+
|
|
190
|
+
### Tuple Encoding (Head + Tail)
|
|
191
|
+
|
|
192
|
+
For a tuple `(T1, T2, ..., TN)`:
|
|
193
|
+
|
|
194
|
+
1. **Head:** For each element:
|
|
195
|
+
- Static: encode value directly
|
|
196
|
+
- Dynamic: encode 2-byte offset to tail
|
|
197
|
+
|
|
198
|
+
2. **Tail:** For each dynamic element:
|
|
199
|
+
- Encode the actual data
|
|
200
|
+
|
|
201
|
+
```
|
|
202
|
+
Example: (uint64, string, uint32, string)
|
|
203
|
+
|
|
204
|
+
Head: [8 bytes uint64][2 byte offset1][4 bytes uint32][2 byte offset2]
|
|
205
|
+
Tail: [string1 data][string2 data]
|
|
206
|
+
|
|
207
|
+
Offsets point to start of each string in tail relative to head start.
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Boolean Packing
|
|
211
|
+
|
|
212
|
+
Up to 8 consecutive booleans are packed into a single byte (MSB first):
|
|
213
|
+
|
|
214
|
+
```
|
|
215
|
+
(bool, bool, bool, uint64, bool, bool)
|
|
216
|
+
First 3 bools: packed into 1 byte
|
|
217
|
+
Then uint64: 8 bytes
|
|
218
|
+
Last 2 bools: packed into 1 byte
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Method Invocation
|
|
222
|
+
|
|
223
|
+
### Application Call Structure
|
|
224
|
+
|
|
225
|
+
```
|
|
226
|
+
ApplicationArgs[0]: Method selector (4 bytes)
|
|
227
|
+
ApplicationArgs[1]: First argument (encoded)
|
|
228
|
+
ApplicationArgs[2]: Second argument (encoded)
|
|
229
|
+
...
|
|
230
|
+
ApplicationArgs[15]: 15th+ arguments encoded as tuple (if >15 args)
|
|
231
|
+
|
|
232
|
+
Accounts[]: Referenced accounts (for `account` args)
|
|
233
|
+
ForeignAssets[]: Referenced assets (for `asset` args)
|
|
234
|
+
ForeignApps[]: Referenced apps (for `application` args)
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Return Value
|
|
238
|
+
|
|
239
|
+
Return values are logged with a specific prefix:
|
|
240
|
+
|
|
241
|
+
```
|
|
242
|
+
Log format: 0x151f7c75 + encoded_return_value
|
|
243
|
+
|
|
244
|
+
The prefix 151f7c75 = SHA-512/256("return")[:4]
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Bare Methods
|
|
248
|
+
|
|
249
|
+
Bare methods have no selector and no arguments. They are identified by `NumAppArgs == 0`.
|
|
250
|
+
|
|
251
|
+
## Common Mistakes
|
|
252
|
+
|
|
253
|
+
| Mistake | Problem | Fix |
|
|
254
|
+
|---------|---------|-----|
|
|
255
|
+
| Using native types in ABI | `def foo(x: int)` won't work | Use `arc4.UInt64` for arguments |
|
|
256
|
+
| Returning reference type | `-> Account` is invalid | Return `arc4.Address` instead |
|
|
257
|
+
| Wrong selector | Method not found | Verify signature matches exactly |
|
|
258
|
+
| Missing transaction arg | Transaction not in group | Add preceding transaction |
|
|
259
|
+
| Index out of bounds | Reference type index wrong | Check Accounts/Assets/Apps arrays |
|
|
260
|
+
|
|
261
|
+
## References
|
|
262
|
+
|
|
263
|
+
- [ARC-4 Specification](https://dev.algorand.co/arc-standards/arc-0004/)
|
|
264
|
+
- [ARC-22 Read-only Methods](https://dev.algorand.co/arc-standards/arc-0022/)
|
|
265
|
+
- [ARC-28 Event Logging](https://dev.algorand.co/arc-standards/arc-0028/)
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# Implement ARC Standards
|
|
2
|
+
|
|
3
|
+
ARC (Algorand Request for Comments) standards define conventions for encoding, method calls, and application specifications on Algorand. This reference covers the most essential ARCs for smart contract development.
|
|
4
|
+
|
|
5
|
+
## Key ARCs for Smart Contract Development
|
|
6
|
+
|
|
7
|
+
| ARC | Purpose | When to Use |
|
|
8
|
+
|-----|---------|-------------|
|
|
9
|
+
| **ARC-4** | Application Binary Interface (ABI) | All smart contract method calls, type encoding |
|
|
10
|
+
| **ARC-22** | Read-only method annotation | Methods that don't modify state |
|
|
11
|
+
| **ARC-28** | Event logging specification | Emitting structured events |
|
|
12
|
+
| **ARC-32** | Application Specification (deprecated) | Legacy app specs (use ARC-56 instead) |
|
|
13
|
+
| **ARC-56** | Extended App Description | Modern app specs with full contract metadata |
|
|
14
|
+
|
|
15
|
+
## ARC-4: The Foundation
|
|
16
|
+
|
|
17
|
+
ARC-4 defines how to encode method calls and data types for Algorand smart contracts. It enables interoperability between contracts, clients, wallets, and explorers.
|
|
18
|
+
|
|
19
|
+
### Method Signatures
|
|
20
|
+
|
|
21
|
+
A method signature uniquely identifies a method: `name(arg_types)return_type`
|
|
22
|
+
|
|
23
|
+
- No spaces between elements
|
|
24
|
+
- No argument names, only types
|
|
25
|
+
- `void` for no return value
|
|
26
|
+
|
|
27
|
+
Examples:
|
|
28
|
+
|
|
29
|
+
| Method | Signature |
|
|
30
|
+
|--------|-----------|
|
|
31
|
+
| `add(a: UInt64, b: UInt64) -> UInt128` | `add(uint64,uint64)uint128` |
|
|
32
|
+
| `greet(name: String) -> String` | `greet(string)string` |
|
|
33
|
+
| `transfer(to: Account, amt: UInt64) -> None` | `transfer(account,uint64)void` |
|
|
34
|
+
| `process(p: PaymentTxn, d: Bytes) -> None` | `process(pay,byte[])void` |
|
|
35
|
+
|
|
36
|
+
### Method Selector Calculation
|
|
37
|
+
|
|
38
|
+
The method selector is the first 4 bytes of the SHA-512/256 hash of the method signature:
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
Method signature: add(uint64,uint64)uint128
|
|
42
|
+
SHA-512/256 hash: 8aa3b61f0f1965c3a1cbfa91d46b24e54c67270184ff89dc114e877b1753254a
|
|
43
|
+
Method selector: 8aa3b61f (first 4 bytes)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
import hashlib
|
|
48
|
+
|
|
49
|
+
def get_selector(signature: str) -> bytes:
|
|
50
|
+
"""Calculate ARC-4 method selector."""
|
|
51
|
+
hash_bytes = hashlib.sha512_256(signature.encode()).digest()
|
|
52
|
+
return hash_bytes[:4]
|
|
53
|
+
|
|
54
|
+
# Example
|
|
55
|
+
selector = get_selector("add(uint64,uint64)uint128")
|
|
56
|
+
# Returns: b'\x8a\xa3\xb6\x1f' (hex: 8aa3b61f)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## ARC-32 vs ARC-56
|
|
60
|
+
|
|
61
|
+
| Feature | ARC-32 | ARC-56 |
|
|
62
|
+
|---------|--------|--------|
|
|
63
|
+
| **Status** | Deprecated | Current Standard |
|
|
64
|
+
| **ARC-4 methods** | Yes | Yes |
|
|
65
|
+
| **State schema** | Yes | Yes |
|
|
66
|
+
| **Method hints** | Partial | Full |
|
|
67
|
+
| **Named structs** | No | Yes |
|
|
68
|
+
| **Default argument values** | Limited | Full support |
|
|
69
|
+
| **Source code info** | No | Yes (optional) |
|
|
70
|
+
| **Source maps** | No | Yes (optional) |
|
|
71
|
+
| **ARC-28 events** | No | Yes |
|
|
72
|
+
| **Bare action config** | Yes | Yes |
|
|
73
|
+
| **Template variables** | No | Yes |
|
|
74
|
+
| **Scratch variables** | No | Yes |
|
|
75
|
+
|
|
76
|
+
**Use ARC-56** for all new projects. ARC-32 is maintained for legacy compatibility only.
|
|
77
|
+
|
|
78
|
+
## Important Rules / Guidelines
|
|
79
|
+
|
|
80
|
+
| Rule | Details |
|
|
81
|
+
|------|---------|
|
|
82
|
+
| **ARC-4 types only in ABI** | Use `arc4.UInt64`, `arc4.String`, etc. for method arguments and returns |
|
|
83
|
+
| **Reference types as arguments only** | `account`, `asset`, `application` cannot be return types |
|
|
84
|
+
| **15 argument limit** | Methods with 16+ args encode extras as a tuple in arg 15 |
|
|
85
|
+
| **Return prefix** | Return values are logged with `151f7c75` prefix |
|
|
86
|
+
| **Bare methods have no selector** | Bare calls use `NumAppArgs == 0` for routing |
|
|
87
|
+
|
|
88
|
+
## References
|
|
89
|
+
|
|
90
|
+
- [ARC-4 ABI Details](./implement-arc-standards-arc4.md) - Types, encoding rules, method invocation
|
|
91
|
+
- [ARC-32/56 App Specs](./implement-arc-standards-arc32-arc56.md) - Application specification details
|
|
92
|
+
- [ARC Standards](https://dev.algorand.co/arc-standards/) - Official ARC documentation
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Algorand Examples — WebFetch Reference
|
|
2
|
+
|
|
3
|
+
Quick reference for fetching Algorand code examples using WebFetch with raw GitHub URLs.
|
|
4
|
+
|
|
5
|
+
## Methods
|
|
6
|
+
|
|
7
|
+
| Method | URL Pattern | Purpose |
|
|
8
|
+
|--------|-------------|---------|
|
|
9
|
+
| File contents | `https://raw.githubusercontent.com/{owner}/{repo}/{branch}/{path}` | Read file contents (plain text) |
|
|
10
|
+
| Directory listing | `https://api.github.com/repos/{owner}/{repo}/contents/{path}` | List directory entries (JSON) |
|
|
11
|
+
| Knowledge docs | `get_knowledge_doc` (Algorand MCP) | Algorand developer documentation |
|
|
12
|
+
|
|
13
|
+
## Fetching File Contents
|
|
14
|
+
|
|
15
|
+
Use `raw.githubusercontent.com` to get file contents directly as plain text.
|
|
16
|
+
|
|
17
|
+
**URL Format:**
|
|
18
|
+
```
|
|
19
|
+
https://raw.githubusercontent.com/{owner}/{repo}/{branch}/{path}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Examples:**
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
# Get a specific contract
|
|
26
|
+
WebFetch url:https://raw.githubusercontent.com/algorandfoundation/puya-ts/main/examples/voting/contract.algo.ts
|
|
27
|
+
|
|
28
|
+
# Get a test file
|
|
29
|
+
WebFetch url:https://raw.githubusercontent.com/algorandfoundation/puya-ts/main/examples/voting/contract.spec.ts
|
|
30
|
+
|
|
31
|
+
# Get devportal example
|
|
32
|
+
WebFetch url:https://raw.githubusercontent.com/algorandfoundation/devportal-code-examples/main/projects/typescript-examples/contracts/HelloWorld/contract.algo.ts
|
|
33
|
+
|
|
34
|
+
# Get a Python example
|
|
35
|
+
WebFetch url:https://raw.githubusercontent.com/algorandfoundation/puya/main/examples/voting/contract.py
|
|
36
|
+
|
|
37
|
+
# Get README or docs
|
|
38
|
+
WebFetch url:https://raw.githubusercontent.com/algorandfoundation/algokit-utils-ts/main/README.md
|
|
39
|
+
WebFetch url:https://raw.githubusercontent.com/algorandfoundation/algokit-utils-ts/main/CHANGELOG.md
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Listing Directory Contents
|
|
43
|
+
|
|
44
|
+
Use `api.github.com` to list files in a directory.
|
|
45
|
+
|
|
46
|
+
**URL Format:**
|
|
47
|
+
```
|
|
48
|
+
https://api.github.com/repos/{owner}/{repo}/contents/{path}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Examples:**
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
# List examples directory
|
|
55
|
+
WebFetch url:https://api.github.com/repos/algorandfoundation/puya-ts/contents/examples
|
|
56
|
+
|
|
57
|
+
# List repo root
|
|
58
|
+
WebFetch url:https://api.github.com/repos/algorandfoundation/devportal-code-examples/contents
|
|
59
|
+
|
|
60
|
+
# List TypeScript contracts
|
|
61
|
+
WebFetch url:https://api.github.com/repos/algorandfoundation/devportal-code-examples/contents/projects/typescript-examples/contracts
|
|
62
|
+
|
|
63
|
+
# List Python contracts
|
|
64
|
+
WebFetch url:https://api.github.com/repos/algorandfoundation/devportal-code-examples/contents/projects/python-examples/contracts
|
|
65
|
+
|
|
66
|
+
# List specific branch
|
|
67
|
+
WebFetch url:https://api.github.com/repos/algorandfoundation/puya-ts/contents/examples?ref=main
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Searching for Code Patterns
|
|
71
|
+
|
|
72
|
+
For searching code across repositories, use web search:
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
# Search for BoxMap usage in TypeScript
|
|
76
|
+
Web search: "BoxMap site:github.com/algorandfoundation language:typescript"
|
|
77
|
+
|
|
78
|
+
# Search for inner transactions
|
|
79
|
+
Web search: "itxn site:github.com/algorandfoundation"
|
|
80
|
+
|
|
81
|
+
# Search for ARC-4 implementations
|
|
82
|
+
Web search: "arc4 abimethod site:github.com/algorandfoundation"
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Using Knowledge Base (Algorand MCP)
|
|
86
|
+
|
|
87
|
+
For Algorand developer documentation, use `get_knowledge_doc` or `list_knowledge_docs` from the Algorand MCP server (Remote Full or Local):
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
# List available documents in a category
|
|
91
|
+
list_knowledge_docs { "prefix": "arcs" }
|
|
92
|
+
|
|
93
|
+
# Get specific documentation
|
|
94
|
+
get_knowledge_doc { "documents": ["arcs:specs:arc-0003.md"] }
|
|
95
|
+
get_knowledge_doc { "documents": ["algokit:docs:get-started.md"] }
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**Knowledge categories:** `arcs`, `sdks`, `algokit`, `algokit-utils`, `tealscript`, `puya`, `liquid-auth`, `python`, `developers`, `clis`, `nodes`, `details`
|
|
99
|
+
|
|
100
|
+
## Priority Repositories
|
|
101
|
+
|
|
102
|
+
| Repository | Path | Content |
|
|
103
|
+
|------------|------|---------|
|
|
104
|
+
| `devportal-code-examples` | `projects/typescript-examples/contracts/` | Beginner TypeScript |
|
|
105
|
+
| `devportal-code-examples` | `projects/python-examples/contracts/` | Beginner Python |
|
|
106
|
+
| `puya-ts` | `examples/` | Advanced TypeScript (voting, amm, auction) |
|
|
107
|
+
| `puya` | `examples/` | Advanced Python |
|
|
108
|
+
| `algokit-typescript-template` | `/` | Project template |
|
|
109
|
+
| `algokit-utils-ts` | `src/` | Utility library |
|
|
110
|
+
|
|
111
|
+
## Common Patterns Location
|
|
112
|
+
|
|
113
|
+
| Pattern | Repository | Path |
|
|
114
|
+
|---------|------------|------|
|
|
115
|
+
| Box storage | devportal-code-examples | `contracts/BoxStorage/` |
|
|
116
|
+
| BoxMap | puya-ts | `examples/voting/`, `examples/amm/` |
|
|
117
|
+
| Inner transactions | devportal-code-examples | `contracts/` |
|
|
118
|
+
| ARC-4 methods | puya-ts | `examples/hello_world_arc4/` |
|
|
119
|
+
| State management | devportal-code-examples | `contracts/` |
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
|
|
2
|
+
# Searching Algorand Examples
|
|
3
|
+
|
|
4
|
+
Find working contract examples and code patterns from Algorand Foundation repositories using WebFetch with raw GitHub URLs.
|
|
5
|
+
|
|
6
|
+
## Overview / Core Workflow
|
|
7
|
+
|
|
8
|
+
1. Identify what pattern or example the user needs
|
|
9
|
+
2. Use WebFetch to fetch raw file contents from priority GitHub repositories
|
|
10
|
+
3. Search priority repositories first (devportal-code-examples, puya-ts)
|
|
11
|
+
4. Retrieve the relevant file(s)
|
|
12
|
+
5. Also fetch corresponding test files when applicable
|
|
13
|
+
|
|
14
|
+
## How to proceed
|
|
15
|
+
|
|
16
|
+
1. **Determine what you need:**
|
|
17
|
+
- Looking for a specific file → use WebFetch with the raw GitHub URL
|
|
18
|
+
- Need to browse a directory → use WebFetch with the GitHub API: `https://api.github.com/repos/{owner}/{repo}/contents/{path}`
|
|
19
|
+
- Looking for documentation → use `get_knowledge_doc` from Algorand MCP (Remote Full or Local)
|
|
20
|
+
|
|
21
|
+
2. **Search priority repositories first:**
|
|
22
|
+
|
|
23
|
+
| Priority | Repository | Best For |
|
|
24
|
+
|----------|------------|----------|
|
|
25
|
+
| 1 | `algorandfoundation/devportal-code-examples` | Beginner-friendly patterns |
|
|
26
|
+
| 2 | `algorandfoundation/puya-ts` | Advanced TypeScript examples |
|
|
27
|
+
| 3 | `algorandfoundation/puya` | Python examples |
|
|
28
|
+
| 4 | `algorandfoundation/algokit-*` | Templates and utilities |
|
|
29
|
+
|
|
30
|
+
3. **Fetch files with WebFetch:**
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
# Get a specific file
|
|
34
|
+
WebFetch url:https://raw.githubusercontent.com/algorandfoundation/puya-ts/main/examples/voting/contract.algo.ts
|
|
35
|
+
|
|
36
|
+
# List directory contents (via GitHub API)
|
|
37
|
+
WebFetch url:https://api.github.com/repos/algorandfoundation/puya-ts/contents/examples
|
|
38
|
+
|
|
39
|
+
# Get a README or changelog
|
|
40
|
+
WebFetch url:https://raw.githubusercontent.com/algorandfoundation/algokit-utils-ts/main/CHANGELOG.md
|
|
41
|
+
|
|
42
|
+
# Get devportal examples
|
|
43
|
+
WebFetch url:https://raw.githubusercontent.com/algorandfoundation/devportal-code-examples/main/projects/typescript-examples/contracts/HelloWorld/contract.algo.ts
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
4. **Always fetch test files:**
|
|
47
|
+
- For any contract file, check for corresponding `*.spec.ts` or `*_test.py`
|
|
48
|
+
- Tests show how to call methods and verify behavior
|
|
49
|
+
|
|
50
|
+
## Important Rules / Guidelines
|
|
51
|
+
|
|
52
|
+
- **Search algorandfoundation first** — Official repos have vetted, up-to-date examples
|
|
53
|
+
- **Always include test files** — They demonstrate correct usage patterns
|
|
54
|
+
- **Use raw.githubusercontent.com** for file contents — faster and returns plain text
|
|
55
|
+
- **Use api.github.com** for directory listings — returns JSON with file names and paths
|
|
56
|
+
- **Check file paths in devportal-code-examples:**
|
|
57
|
+
- TypeScript: `projects/typescript-examples/contracts/`
|
|
58
|
+
- Python: `projects/python-examples/contracts/`
|
|
59
|
+
- **Prefer puya-ts/examples for complex patterns** — Voting, AMM, auction examples are comprehensive
|
|
60
|
+
|
|
61
|
+
## Raw GitHub URL Patterns
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
# File contents (plain text)
|
|
65
|
+
https://raw.githubusercontent.com/{owner}/{repo}/{branch}/{path}
|
|
66
|
+
|
|
67
|
+
# Directory listing (JSON)
|
|
68
|
+
https://api.github.com/repos/{owner}/{repo}/contents/{path}
|
|
69
|
+
|
|
70
|
+
# Search code (JSON) - use web search as alternative
|
|
71
|
+
https://api.github.com/search/code?q={query}+org:algorandfoundation+language:typescript
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Common Variations / Edge Cases
|
|
75
|
+
|
|
76
|
+
| Scenario | Approach |
|
|
77
|
+
|----------|----------|
|
|
78
|
+
| Pattern not found in algorandfoundation | Use web search for broader GitHub results |
|
|
79
|
+
| Need Python instead of TypeScript | Use `algorandfoundation/puya` instead of `puya-ts` |
|
|
80
|
+
| Looking for deployment patterns | Check `algokit-*-template` repos |
|
|
81
|
+
| Need ARC standard implementation | Use `get_knowledge_doc` with `arcs` category |
|
|
82
|
+
| Need documentation | Use `get_knowledge_doc` or `list_knowledge_docs` from Algorand MCP |
|
|
83
|
+
|
|
84
|
+
## References / Further Reading
|
|
85
|
+
|
|
86
|
+
- [Tool Reference](./search-algorand-examples-reference.md)
|
|
87
|
+
- [DevPortal Code Examples](https://github.com/algorandfoundation/devportal-code-examples)
|
|
88
|
+
- [Puya TypeScript Examples](https://github.com/algorandfoundation/puya-ts/tree/main/examples)
|
|
89
|
+
- [Algorand Developer Portal](https://dev.algorand.co/)
|