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.
Files changed (112) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +112 -0
  3. package/index.ts +361 -0
  4. package/lib/mcp-servers.ts +14 -0
  5. package/lib/x402-fetch.ts +213 -0
  6. package/memory/algorand-plugin.md +82 -0
  7. package/openclaw.plugin.json +30 -0
  8. package/package.json +38 -0
  9. package/setup.ts +80 -0
  10. package/skills/algorand-development/SKILL.md +90 -0
  11. package/skills/algorand-development/references/build-smart-contracts-reference.md +79 -0
  12. package/skills/algorand-development/references/build-smart-contracts.md +52 -0
  13. package/skills/algorand-development/references/create-project-reference.md +86 -0
  14. package/skills/algorand-development/references/create-project.md +89 -0
  15. package/skills/algorand-development/references/implement-arc-standards-arc32-arc56.md +396 -0
  16. package/skills/algorand-development/references/implement-arc-standards-arc4.md +265 -0
  17. package/skills/algorand-development/references/implement-arc-standards.md +92 -0
  18. package/skills/algorand-development/references/search-algorand-examples-reference.md +119 -0
  19. package/skills/algorand-development/references/search-algorand-examples.md +89 -0
  20. package/skills/algorand-development/references/troubleshoot-errors-contract.md +373 -0
  21. package/skills/algorand-development/references/troubleshoot-errors-transaction.md +599 -0
  22. package/skills/algorand-development/references/troubleshoot-errors.md +105 -0
  23. package/skills/algorand-development/references/use-algokit-cli-reference.md +228 -0
  24. package/skills/algorand-development/references/use-algokit-cli.md +64 -0
  25. package/skills/algorand-interaction/SKILL.md +223 -0
  26. package/skills/algorand-interaction/references/algorand-mcp.md +743 -0
  27. package/skills/algorand-interaction/references/examples-algorand-mcp.md +647 -0
  28. package/skills/algorand-python/SKILL.md +95 -0
  29. package/skills/algorand-python/references/build-smart-contracts-decorators.md +413 -0
  30. package/skills/algorand-python/references/build-smart-contracts-reference.md +55 -0
  31. package/skills/algorand-python/references/build-smart-contracts-storage.md +452 -0
  32. package/skills/algorand-python/references/build-smart-contracts-transactions.md +445 -0
  33. package/skills/algorand-python/references/build-smart-contracts-types.md +438 -0
  34. package/skills/algorand-python/references/build-smart-contracts.md +82 -0
  35. package/skills/algorand-python/references/create-project-reference.md +55 -0
  36. package/skills/algorand-python/references/create-project.md +75 -0
  37. package/skills/algorand-python/references/implement-arc-standards-arc32-arc56.md +101 -0
  38. package/skills/algorand-python/references/implement-arc-standards-arc4.md +154 -0
  39. package/skills/algorand-python/references/implement-arc-standards.md +39 -0
  40. package/skills/algorand-python/references/troubleshoot-errors-contract.md +355 -0
  41. package/skills/algorand-python/references/troubleshoot-errors-transaction.md +430 -0
  42. package/skills/algorand-python/references/troubleshoot-errors.md +46 -0
  43. package/skills/algorand-python/references/use-algokit-utils-reference.md +350 -0
  44. package/skills/algorand-python/references/use-algokit-utils.md +76 -0
  45. package/skills/algorand-typescript/SKILL.md +131 -0
  46. package/skills/algorand-typescript/references/algorand-ts-migration-from-beta.md +448 -0
  47. package/skills/algorand-typescript/references/algorand-ts-migration-from-tealscript.md +487 -0
  48. package/skills/algorand-typescript/references/algorand-ts-migration.md +102 -0
  49. package/skills/algorand-typescript/references/algorand-typescript-syntax-methods-and-abi.md +134 -0
  50. package/skills/algorand-typescript/references/algorand-typescript-syntax-reference.md +58 -0
  51. package/skills/algorand-typescript/references/algorand-typescript-syntax-storage.md +154 -0
  52. package/skills/algorand-typescript/references/algorand-typescript-syntax-transactions.md +187 -0
  53. package/skills/algorand-typescript/references/algorand-typescript-syntax-types-and-values.md +150 -0
  54. package/skills/algorand-typescript/references/algorand-typescript-syntax.md +84 -0
  55. package/skills/algorand-typescript/references/build-smart-contracts-reference.md +52 -0
  56. package/skills/algorand-typescript/references/build-smart-contracts.md +74 -0
  57. package/skills/algorand-typescript/references/call-smart-contracts-reference.md +237 -0
  58. package/skills/algorand-typescript/references/call-smart-contracts.md +183 -0
  59. package/skills/algorand-typescript/references/create-project-reference.md +53 -0
  60. package/skills/algorand-typescript/references/create-project.md +86 -0
  61. package/skills/algorand-typescript/references/deploy-react-frontend-examples.md +527 -0
  62. package/skills/algorand-typescript/references/deploy-react-frontend-reference.md +412 -0
  63. package/skills/algorand-typescript/references/deploy-react-frontend.md +239 -0
  64. package/skills/algorand-typescript/references/implement-arc-standards-arc32-arc56.md +73 -0
  65. package/skills/algorand-typescript/references/implement-arc-standards-arc4.md +126 -0
  66. package/skills/algorand-typescript/references/implement-arc-standards.md +44 -0
  67. package/skills/algorand-typescript/references/test-smart-contracts-examples.md +245 -0
  68. package/skills/algorand-typescript/references/test-smart-contracts-unit-tests.md +147 -0
  69. package/skills/algorand-typescript/references/test-smart-contracts.md +127 -0
  70. package/skills/algorand-typescript/references/troubleshoot-errors-contract.md +296 -0
  71. package/skills/algorand-typescript/references/troubleshoot-errors-transaction.md +438 -0
  72. package/skills/algorand-typescript/references/troubleshoot-errors.md +56 -0
  73. package/skills/algorand-typescript/references/use-algokit-utils-reference.md +342 -0
  74. package/skills/algorand-typescript/references/use-algokit-utils.md +74 -0
  75. package/skills/algorand-x402-python/SKILL.md +113 -0
  76. package/skills/algorand-x402-python/references/create-python-x402-client-examples.md +469 -0
  77. package/skills/algorand-x402-python/references/create-python-x402-client-reference.md +313 -0
  78. package/skills/algorand-x402-python/references/create-python-x402-client.md +207 -0
  79. package/skills/algorand-x402-python/references/create-python-x402-facilitator-examples.md +924 -0
  80. package/skills/algorand-x402-python/references/create-python-x402-facilitator-reference.md +629 -0
  81. package/skills/algorand-x402-python/references/create-python-x402-facilitator.md +408 -0
  82. package/skills/algorand-x402-python/references/create-python-x402-server-examples.md +703 -0
  83. package/skills/algorand-x402-python/references/create-python-x402-server-reference.md +303 -0
  84. package/skills/algorand-x402-python/references/create-python-x402-server.md +221 -0
  85. package/skills/algorand-x402-python/references/explain-algorand-x402-python-examples.md +605 -0
  86. package/skills/algorand-x402-python/references/explain-algorand-x402-python-reference.md +315 -0
  87. package/skills/algorand-x402-python/references/explain-algorand-x402-python.md +167 -0
  88. package/skills/algorand-x402-python/references/use-python-x402-core-avm-examples.md +554 -0
  89. package/skills/algorand-x402-python/references/use-python-x402-core-avm-reference.md +278 -0
  90. package/skills/algorand-x402-python/references/use-python-x402-core-avm.md +166 -0
  91. package/skills/algorand-x402-typescript/SKILL.md +129 -0
  92. package/skills/algorand-x402-typescript/references/create-typescript-x402-client-examples.md +879 -0
  93. package/skills/algorand-x402-typescript/references/create-typescript-x402-client-reference.md +371 -0
  94. package/skills/algorand-x402-typescript/references/create-typescript-x402-client.md +236 -0
  95. package/skills/algorand-x402-typescript/references/create-typescript-x402-facilitator-examples.md +875 -0
  96. package/skills/algorand-x402-typescript/references/create-typescript-x402-facilitator-reference.md +461 -0
  97. package/skills/algorand-x402-typescript/references/create-typescript-x402-facilitator.md +270 -0
  98. package/skills/algorand-x402-typescript/references/create-typescript-x402-nextjs-examples.md +1181 -0
  99. package/skills/algorand-x402-typescript/references/create-typescript-x402-nextjs-reference.md +360 -0
  100. package/skills/algorand-x402-typescript/references/create-typescript-x402-nextjs.md +251 -0
  101. package/skills/algorand-x402-typescript/references/create-typescript-x402-paywall-examples.md +870 -0
  102. package/skills/algorand-x402-typescript/references/create-typescript-x402-paywall-reference.md +323 -0
  103. package/skills/algorand-x402-typescript/references/create-typescript-x402-paywall.md +281 -0
  104. package/skills/algorand-x402-typescript/references/create-typescript-x402-server-examples.md +1135 -0
  105. package/skills/algorand-x402-typescript/references/create-typescript-x402-server-reference.md +382 -0
  106. package/skills/algorand-x402-typescript/references/create-typescript-x402-server.md +216 -0
  107. package/skills/algorand-x402-typescript/references/explain-algorand-x402-typescript-examples.md +616 -0
  108. package/skills/algorand-x402-typescript/references/explain-algorand-x402-typescript-reference.md +323 -0
  109. package/skills/algorand-x402-typescript/references/explain-algorand-x402-typescript.md +232 -0
  110. package/skills/algorand-x402-typescript/references/use-typescript-x402-core-avm-examples.md +1417 -0
  111. package/skills/algorand-x402-typescript/references/use-typescript-x402-core-avm-reference.md +504 -0
  112. package/skills/algorand-x402-typescript/references/use-typescript-x402-core-avm.md +158 -0
@@ -0,0 +1,278 @@
1
+ # x402-avm Python Core and AVM Mechanism Reference
2
+
3
+ Detailed API reference for the x402-avm Python package core components and AVM mechanism.
4
+
5
+ ## Core Package Exports
6
+
7
+ ### Client Components
8
+
9
+ | Export | Import | Description |
10
+ |--------|--------|-------------|
11
+ | `x402Client` | `from x402 import x402Client` | Async client that handles 402 responses automatically |
12
+ | `x402ClientSync` | `from x402 import x402ClientSync` | Synchronous variant of x402Client |
13
+
14
+ ### Server Components
15
+
16
+ | Export | Import | Description |
17
+ |--------|--------|-------------|
18
+ | `x402ResourceServer` | `from x402 import x402ResourceServer` | Async resource server with payment middleware |
19
+ | `x402ResourceServerSync` | `from x402 import x402ResourceServerSync` | Synchronous variant |
20
+
21
+ ### Facilitator Components
22
+
23
+ | Export | Import | Description |
24
+ |--------|--------|-------------|
25
+ | `x402Facilitator` | `from x402 import x402Facilitator` | Async facilitator for payment verification and settlement |
26
+ | `x402FacilitatorSync` | `from x402 import x402FacilitatorSync` | Synchronous variant |
27
+
28
+ ### Schema Types
29
+
30
+ | Export | Import | Description |
31
+ |--------|--------|-------------|
32
+ | `PaymentRequirements` | `from x402.schemas import PaymentRequirements` | V2 payment requirements structure |
33
+ | `PaymentPayload` | `from x402.schemas import PaymentPayload` | Payment payload sent in PAYMENT-SIGNATURE header |
34
+ | `Network` | `from x402.schemas import Network` | Network identifier type (CAIP-2 string) |
35
+
36
+ ---
37
+
38
+ ## AVM Mechanism Exports
39
+
40
+ ### Signer Protocols
41
+
42
+ | Export | Import | Description |
43
+ |--------|--------|-------------|
44
+ | `ClientAvmSigner` | `from x402.mechanisms.avm.signer import ClientAvmSigner` | Protocol for client-side transaction signing |
45
+ | `FacilitatorAvmSigner` | `from x402.mechanisms.avm.signer import FacilitatorAvmSigner` | Protocol for facilitator-side operations |
46
+
47
+ ### Scheme Classes
48
+
49
+ | Export | Import | Description |
50
+ |--------|--------|-------------|
51
+ | `ExactAvmScheme` | `from x402.mechanisms.avm.exact import ExactAvmScheme` | Base AVM exact payment scheme |
52
+ | `ExactAvmClientScheme` | `from x402.mechanisms.avm.exact import ExactAvmClientScheme` | Client-specific scheme |
53
+ | `ExactAvmServerScheme` | `from x402.mechanisms.avm.exact import ExactAvmServerScheme` | Server-specific scheme |
54
+ | `ExactAvmFacilitatorScheme` | `from x402.mechanisms.avm.exact import ExactAvmFacilitatorScheme` | Facilitator-specific scheme |
55
+
56
+ ### Registration Functions
57
+
58
+ | Function | Import | Description |
59
+ |----------|--------|-------------|
60
+ | `register_exact_avm_client` | `from x402.mechanisms.avm.exact import register_exact_avm_client` | Register AVM on a client |
61
+ | `register_exact_avm_server` | `from x402.mechanisms.avm.exact import register_exact_avm_server` | Register AVM on a server |
62
+ | `register_exact_avm_facilitator` | `from x402.mechanisms.avm.exact import register_exact_avm_facilitator` | Register AVM on a facilitator |
63
+
64
+ ---
65
+
66
+ ## Constants Reference
67
+
68
+ ### Network Identifiers
69
+
70
+ | Constant | Value | Import |
71
+ |----------|-------|--------|
72
+ | `ALGORAND_MAINNET_CAIP2` | `"algorand:wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8="` | `from x402.mechanisms.avm.constants import ALGORAND_MAINNET_CAIP2` |
73
+ | `ALGORAND_TESTNET_CAIP2` | `"algorand:SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI="` | `from x402.mechanisms.avm.constants import ALGORAND_TESTNET_CAIP2` |
74
+ | `SUPPORTED_NETWORKS` | `[MAINNET_CAIP2, TESTNET_CAIP2]` | `from x402.mechanisms.avm.constants import SUPPORTED_NETWORKS` |
75
+
76
+ ### Genesis Hashes
77
+
78
+ | Constant | Value |
79
+ |----------|-------|
80
+ | `MAINNET_GENESIS_HASH` | `"wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8="` |
81
+ | `TESTNET_GENESIS_HASH` | `"SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI="` |
82
+
83
+ ### V1 Compatibility
84
+
85
+ | Constant | Value | Description |
86
+ |----------|-------|-------------|
87
+ | `V1_NETWORKS` | `["algorand-mainnet", "algorand-testnet"]` | Legacy network names |
88
+ | `V1_TO_V2_NETWORK_MAP` | `{"algorand-mainnet": CAIP2, ...}` | V1 to CAIP-2 mapping |
89
+ | `V2_TO_V1_NETWORK_MAP` | `{CAIP2: "algorand-mainnet", ...}` | CAIP-2 to V1 mapping |
90
+
91
+ ### USDC Configuration
92
+
93
+ | Constant | Value | Description |
94
+ |----------|-------|-------------|
95
+ | `USDC_MAINNET_ASA_ID` | `31566704` | Mainnet USDC ASA ID |
96
+ | `USDC_TESTNET_ASA_ID` | `10458941` | Testnet USDC ASA ID |
97
+ | `DEFAULT_DECIMALS` | `6` | USDC decimal places |
98
+
99
+ ### Transaction Limits
100
+
101
+ | Constant | Value | Description |
102
+ |----------|-------|-------------|
103
+ | `MAX_GROUP_SIZE` | `16` | Maximum transactions in an atomic group |
104
+ | `MIN_TXN_FEE` | `1000` | Minimum transaction fee in microAlgos |
105
+
106
+ ### Algod Endpoints
107
+
108
+ | Constant | Value | Description |
109
+ |----------|-------|-------------|
110
+ | `FALLBACK_ALGOD_MAINNET` | `"https://mainnet-api.algonode.cloud"` | Default mainnet Algod URL |
111
+ | `FALLBACK_ALGOD_TESTNET` | `"https://testnet-api.algonode.cloud"` | Default testnet Algod URL |
112
+ | `MAINNET_ALGOD_URL` | `env ALGOD_MAINNET_URL` or fallback | Resolved mainnet URL |
113
+ | `TESTNET_ALGOD_URL` | `env ALGOD_TESTNET_URL` or fallback | Resolved testnet URL |
114
+ | `MAINNET_INDEXER_URL` | `env` or AlgoNode | Mainnet indexer URL |
115
+ | `TESTNET_INDEXER_URL` | `env` or AlgoNode | Testnet indexer URL |
116
+
117
+ ### NETWORK_CONFIGS Structure
118
+
119
+ ```python
120
+ NETWORK_CONFIGS = {
121
+ ALGORAND_TESTNET_CAIP2: {
122
+ "algod_url": "https://testnet-api.algonode.cloud",
123
+ "indexer_url": "https://testnet-idx.algonode.cloud",
124
+ "genesis_hash": "SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=",
125
+ "genesis_id": "testnet-v1.0",
126
+ "default_asset": {"asa_id": 10458941, "name": "USDC", "decimals": 6},
127
+ },
128
+ ALGORAND_MAINNET_CAIP2: {
129
+ "algod_url": "https://mainnet-api.algonode.cloud",
130
+ "indexer_url": "https://mainnet-idx.algonode.cloud",
131
+ "genesis_hash": "wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=",
132
+ "genesis_id": "mainnet-v1.0",
133
+ "default_asset": {"asa_id": 31566704, "name": "USDC", "decimals": 6},
134
+ },
135
+ }
136
+ ```
137
+
138
+ ---
139
+
140
+ ## Utility Functions Reference
141
+
142
+ ### Address Validation
143
+
144
+ | Function | Signature | Description |
145
+ |----------|-----------|-------------|
146
+ | `is_valid_address` | `(address: str) -> bool` | Validate 58-character Algorand address |
147
+
148
+ ### Amount Conversion
149
+
150
+ | Function | Signature | Description |
151
+ |----------|-----------|-------------|
152
+ | `to_atomic_amount` | `(amount: float, decimals: int = 6) -> int` | Convert decimal to atomic units |
153
+ | `from_atomic_amount` | `(amount: int, decimals: int = 6) -> float` | Convert atomic units to decimal |
154
+
155
+ ### Transaction Encoding/Decoding
156
+
157
+ | Function | Signature | Description |
158
+ |----------|-----------|-------------|
159
+ | `decode_transaction_bytes` | `(raw_bytes: bytes) -> DecodedTransactionInfo` | Decode raw msgpack transaction |
160
+ | `decode_base64_transaction` | `(b64_str: str) -> DecodedTransactionInfo` | Decode base64-encoded transaction |
161
+ | `decode_payment_group` | `(payment_group: list[str], payment_index: int) -> DecodedGroupInfo` | Decode a full payment group |
162
+ | `encode_transaction_group` | `(raw_bytes_list: list[bytes]) -> list[str]` | Encode transaction list to base64 |
163
+
164
+ ### DecodedTransactionInfo Fields
165
+
166
+ | Field | Type | Description |
167
+ |-------|------|-------------|
168
+ | `type` | `str` | Transaction type: `"pay"`, `"axfer"`, `"appl"`, etc. |
169
+ | `sender` | `str` | Sender Algorand address |
170
+ | `receiver` | `str` or `None` | Receiver address (payments/transfers) |
171
+ | `fee` | `int` | Transaction fee in microAlgos |
172
+ | `is_signed` | `bool` | Whether the transaction is signed |
173
+ | `asset_amount` | `int` or `None` | Asset amount (for asset transfers) |
174
+ | `asset_id` | `int` or `None` | ASA ID (for asset transfers) |
175
+
176
+ ### DecodedGroupInfo Fields
177
+
178
+ | Field | Type | Description |
179
+ |-------|------|-------------|
180
+ | `transactions` | `list[DecodedTransactionInfo]` | All decoded transactions |
181
+ | `group_id` | `str` | Base64-encoded group ID |
182
+ | `total_fee` | `int` | Sum of all transaction fees |
183
+ | `has_fee_payer` | `bool` | Whether a fee payer transaction is detected |
184
+ | `fee_payer_index` | `int` or `None` | Index of the fee payer transaction |
185
+
186
+ ### Network Utilities
187
+
188
+ | Function | Signature | Description |
189
+ |----------|-----------|-------------|
190
+ | `normalize_network` | `(network: str) -> str` | Convert V1 name or CAIP-2 to CAIP-2 |
191
+ | `is_valid_network` | `(network: str) -> bool` | Check if network is supported |
192
+ | `get_network_config` | `(network: str) -> dict` | Get full network configuration |
193
+ | `get_usdc_asa_id` | `(network: str) -> int` | Get USDC ASA ID for network |
194
+ | `get_genesis_hash` | `(network: str) -> str` | Get genesis hash for network |
195
+ | `network_from_genesis_hash` | `(hash: str) -> str` | Resolve CAIP-2 from genesis hash |
196
+
197
+ ### Security Validation
198
+
199
+ | Function | Signature | Description |
200
+ |----------|-----------|-------------|
201
+ | `validate_no_security_risks` | `(info: DecodedTransactionInfo) -> str or None` | Check for rekey, close-to, blocked types |
202
+ | `validate_fee_payer_transaction` | `(info: DecodedTransactionInfo, expected_fee_payer: str) -> str or None` | Validate fee payer txn structure |
203
+ | `is_blocked_transaction_type` | `(type: str) -> bool` | Check if transaction type is blocked |
204
+
205
+ ---
206
+
207
+ ## Encoding Boundary Patterns
208
+
209
+ The Python `algosdk` (v2.11.1) uses base64 strings at API boundaries, while the x402 SDK protocol uses raw bytes internally:
210
+
211
+ | Direction | Pattern |
212
+ |-----------|---------|
213
+ | Raw bytes to algosdk | `encoding.msgpack_decode(base64.b64encode(raw_bytes).decode("utf-8"))` |
214
+ | algosdk to raw bytes | `base64.b64decode(encoding.msgpack_encode(obj))` |
215
+ | Sign transaction | `txn_obj.sign(base64.b64encode(secret_key).decode())` |
216
+ | Address from key | `encoding.encode_address(secret_key[32:])` |
217
+
218
+ ### Comparison with TypeScript algosdk
219
+
220
+ | Operation | Python algosdk | TypeScript algosdk |
221
+ |-----------|---------------|-------------------|
222
+ | Decode unsigned txn | `msgpack_decode(base64_string)` | `decodeUnsignedTransaction(Uint8Array)` |
223
+ | Encode txn | `msgpack_encode(obj)` returns base64 | `txn.toByte()` returns `Uint8Array` |
224
+ | Sign | `txn.sign(base64_key_string)` | `signTransaction(txn, Uint8Array)` |
225
+
226
+ ---
227
+
228
+ ## Fee Abstraction Flow
229
+
230
+ Fee abstraction uses Algorand atomic transaction groups with pooled fees:
231
+
232
+ ```
233
+ Step 1: Create 2-txn atomic group
234
+ Txn 0: USDC transfer (sender -> receiver, fee = 0)
235
+ Txn 1: Self-payment (fee_payer -> fee_payer, fee = 2 * MIN_TXN_FEE)
236
+
237
+ Step 2: Assign group ID
238
+ gid = calculate_group_id([txn_0, txn_1])
239
+ txn_0.group = gid
240
+ txn_1.group = gid
241
+
242
+ Step 3: Client signs Txn 0, leaves Txn 1 unsigned
243
+ Step 4: Client sends paymentGroup = [signed_txn_0, unsigned_txn_1]
244
+ Step 5: Facilitator signs Txn 1, submits atomic group
245
+ Step 6: Both execute atomically (all-or-nothing)
246
+ ```
247
+
248
+ **Security guarantees:**
249
+ - Fee payer Txn 1 must be a self-payment (receiver == sender) with amount == 0
250
+ - No rekey, close-to, or other dangerous fields
251
+ - Fee is capped at a reasonable maximum
252
+ - Atomic group ensures all-or-nothing execution
253
+
254
+ ---
255
+
256
+ ## Installation
257
+
258
+ ```bash
259
+ # Core + AVM mechanism
260
+ pip install "x402-avm[avm]"
261
+
262
+ # With web framework
263
+ pip install "x402-avm[avm,fastapi]"
264
+ pip install "x402-avm[avm,flask]"
265
+
266
+ # Multi-chain
267
+ pip install "x402-avm[all]"
268
+ ```
269
+
270
+ ---
271
+
272
+ ## External Resources
273
+
274
+ - [x402-avm Examples Repository](https://github.com/GoPlausible/x402-avm/tree/branch-v2-algorand-publish/examples/)
275
+ - [x402-avm AVM Documentation](https://github.com/GoPlausible/.github/blob/main/profile/algorand-x402-documentation/)
276
+ - [algosdk Python SDK](https://py-algorand-sdk.readthedocs.io/)
277
+ - [Algorand Developer Portal](https://developer.algorand.org/)
278
+ - [CAIP-2 Chain ID Specification](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md)
@@ -0,0 +1,166 @@
1
+ # Using x402-avm Python Core and AVM Mechanism
2
+
3
+ Use the x402-avm Python package core components and AVM mechanism directly for building custom payment integrations on Algorand.
4
+
5
+ ## Prerequisites
6
+
7
+ Before using this skill, ensure:
8
+
9
+ 1. **Python 3.10+** is installed
10
+ 2. **x402-avm package** is available: `pip install "x402-avm[avm]"`
11
+ 3. **Understanding of x402 payment flow** -- client sends payment, server returns 402, facilitator verifies/settles
12
+
13
+ ## Core Architecture
14
+
15
+ The x402-avm Python SDK has two layers:
16
+
17
+ ```
18
+ x402-avm Core AVM Mechanism
19
+ +----------------------------------+ +----------------------------------+
20
+ | x402Client / x402ClientSync | | ClientAvmSigner (Protocol) |
21
+ | x402ResourceServer / ...Sync | | FacilitatorAvmSigner (Protocol) |
22
+ | x402Facilitator / ...Sync | | ExactAvmScheme |
23
+ | schemas, types | | constants, utils |
24
+ +----------------------------------+ +----------------------------------+
25
+ | |
26
+ +--- register_exact_avm_* ---------------+
27
+ ```
28
+
29
+ ## How to Proceed
30
+
31
+ ### Step 1: Install the Package
32
+
33
+ ```bash
34
+ # Core + AVM mechanism
35
+ pip install "x402-avm[avm]"
36
+
37
+ # With a web framework
38
+ pip install "x402-avm[avm,fastapi]"
39
+ pip install "x402-avm[avm,flask]"
40
+ ```
41
+
42
+ ### Step 2: Understand the Signer Protocols
43
+
44
+ The SDK defines signer protocols (structural typing -- no inheritance required) that separate protocol definitions from implementations.
45
+
46
+ **ClientAvmSigner** -- for clients making payments:
47
+
48
+ ```python
49
+ from x402.mechanisms.avm.signer import ClientAvmSigner
50
+
51
+ class ClientAvmSigner(Protocol):
52
+ @property
53
+ def address(self) -> str:
54
+ """58-character Algorand address."""
55
+ ...
56
+
57
+ def sign_transactions(
58
+ self,
59
+ unsigned_txns: list[bytes],
60
+ indexes_to_sign: list[int],
61
+ ) -> list[bytes | None]:
62
+ """Sign specified transactions in a group."""
63
+ ...
64
+ ```
65
+
66
+ **FacilitatorAvmSigner** -- for facilitators verifying/settling payments:
67
+
68
+ ```python
69
+ from x402.mechanisms.avm.signer import FacilitatorAvmSigner
70
+
71
+ class FacilitatorAvmSigner(Protocol):
72
+ def get_addresses(self) -> list[str]: ...
73
+ def sign_transaction(self, txn_bytes: bytes, fee_payer: str, network: str) -> bytes: ...
74
+ def sign_group(self, group_bytes: list[bytes], fee_payer: str, indexes_to_sign: list[int], network: str) -> list[bytes]: ...
75
+ def simulate_group(self, group_bytes: list[bytes], network: str) -> None: ...
76
+ def send_group(self, group_bytes: list[bytes], network: str) -> str: ...
77
+ def confirm_transaction(self, txid: str, network: str, rounds: int = 4) -> None: ...
78
+ ```
79
+
80
+ ### Step 3: Use Constants
81
+
82
+ ```python
83
+ from x402.mechanisms.avm.constants import (
84
+ ALGORAND_TESTNET_CAIP2, # "algorand:SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI="
85
+ ALGORAND_MAINNET_CAIP2, # "algorand:wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8="
86
+ USDC_TESTNET_ASA_ID, # 10458941
87
+ USDC_MAINNET_ASA_ID, # 31566704
88
+ MIN_TXN_FEE, # 1000
89
+ MAX_GROUP_SIZE, # 16
90
+ NETWORK_CONFIGS,
91
+ )
92
+ ```
93
+
94
+ ### Step 4: Use Utility Functions
95
+
96
+ ```python
97
+ from x402.mechanisms.avm.utils import (
98
+ is_valid_address,
99
+ to_atomic_amount,
100
+ from_atomic_amount,
101
+ decode_transaction_bytes,
102
+ normalize_network,
103
+ get_usdc_asa_id,
104
+ )
105
+
106
+ # Validate address
107
+ is_valid_address("AAAA...") # True/False
108
+
109
+ # Convert amounts
110
+ to_atomic_amount(1.50) # 1500000
111
+ from_atomic_amount(100000) # 0.1
112
+
113
+ # Decode transactions
114
+ info = decode_transaction_bytes(raw_txn_bytes)
115
+ print(info.type, info.sender, info.fee, info.is_signed)
116
+ ```
117
+
118
+ ### Step 5: Register Schemes
119
+
120
+ ```python
121
+ from x402 import x402Client
122
+ from x402.mechanisms.avm.exact import register_exact_avm_client
123
+
124
+ client = x402Client()
125
+ register_exact_avm_client(client, signer)
126
+
127
+ # Now client.fetch() handles 402 responses automatically
128
+ response = await client.fetch("https://api.example.com/paid-resource")
129
+ ```
130
+
131
+ ### Step 6: Understand Fee Abstraction
132
+
133
+ Fee abstraction uses Algorand's atomic transaction groups and pooled fees:
134
+
135
+ ```
136
+ Transaction 0: USDC transfer (client -> resource owner, fee = 0)
137
+ Transaction 1: Self-payment (fee payer -> fee payer, fee covers both txns)
138
+
139
+ Client signs Txn 0, Facilitator signs Txn 1
140
+ Both execute atomically (all-or-nothing)
141
+ ```
142
+
143
+ ## Important Rules / Guidelines
144
+
145
+ 1. **Signer separation** -- Protocol definitions live in the SDK (`signer.py`), implementations live in examples. Zero algosdk imports in SDK core.
146
+ 2. **First-class AVM** -- AVM is treated identically to EVM/SVM. Never conditional, always registered unconditionally.
147
+ 3. **algosdk encoding boundaries** -- `msgpack_decode()` expects base64 string. `msgpack_encode()` returns base64 string. The SDK protocol passes raw msgpack bytes between methods. Convert at boundaries.
148
+ 4. **Import constants from SDK** -- Use `ALGORAND_TESTNET_CAIP2` from imports, not hardcoded strings, in SDK code.
149
+ 5. **Raw bytes contract** -- The x402 SDK passes raw msgpack bytes between signer methods. This matches the @txnlab/use-wallet ecosystem standard.
150
+
151
+ ## Common Errors / Troubleshooting
152
+
153
+ | Error | Cause | Solution |
154
+ |-------|-------|----------|
155
+ | `ImportError: x402.mechanisms.avm` | Missing `[avm]` extra | Install with `pip install "x402-avm[avm]"` |
156
+ | `msgpack_decode expects string` | Passing raw bytes | Wrap: `base64.b64encode(raw).decode()` |
157
+ | `Invalid address` | Wrong address format | Must be 58-character Algorand address |
158
+ | `to_atomic_amount overflow` | Value too large | Check decimal places (6 for USDC/ALGO) |
159
+ | `Network not supported` | Unregistered network | Register with `register_exact_avm_*` first |
160
+
161
+ ## References / Further Reading
162
+
163
+ - [use-python-x402-core-avm-reference.md](./use-python-x402-core-avm-reference.md) -- Detailed API reference for all exports
164
+ - [use-python-x402-core-avm-examples.md](./use-python-x402-core-avm-examples.md) -- Complete code examples
165
+ - [x402-avm AVM Documentation](https://github.com/GoPlausible/.github/blob/main/profile/algorand-x402-documentation/)
166
+ - [Examples Repository](https://github.com/GoPlausible/x402-avm/tree/branch-v2-algorand-publish/examples/)
@@ -0,0 +1,129 @@
1
+ ---
2
+ name: algorand-x402-typescript
3
+ description: Comprehensive guide for building x402 HTTP-native payment applications on Algorand using TypeScript. This is the parent skill that aggregates all TypeScript x402 sub-skills. Use when working with x402 payments in TypeScript/JavaScript, building clients, servers, facilitators, paywalls, or Next.js apps with Algorand x402, or when explaining x402 concepts to TypeScript developers. Strong triggers include "x402 TypeScript", "x402 Algorand TypeScript", "@x402-avm", "payment protocol TypeScript", "402 payment TypeScript", "x402 client fetch axios", "x402 server express hono", "x402 facilitator TypeScript", "x402 paywall", "x402 Next.js", "x402 core avm TypeScript", "explain x402 TypeScript", "teach x402".
4
+ ---
5
+
6
+ # x402 on Algorand - TypeScript
7
+
8
+ This is the aggregated parent skill for all x402 HTTP-native payment protocol skills targeting TypeScript/JavaScript. Use the reference files below to find detailed guidance for each component.
9
+
10
+ ## TypeScript Quick Start
11
+
12
+ ```bash
13
+ # Core + AVM mechanism
14
+ npm install @x402-avm/core @x402-avm/avm algosdk
15
+
16
+ # Server middleware (pick one)
17
+ npm install @x402-avm/express # Express.js
18
+ npm install @x402-avm/hono # Hono
19
+ npm install @x402-avm/next # Next.js
20
+
21
+ # Client (pick one)
22
+ npm install @x402-avm/fetch # Fetch API
23
+ npm install @x402-avm/axios # Axios
24
+ ```
25
+
26
+ ### Register AVM Scheme
27
+
28
+ Every component registers the AVM exact scheme unconditionally — no environment variable guards:
29
+
30
+ ```typescript
31
+ // Client
32
+ import { registerExactAvmScheme } from "@x402-avm/avm/exact/client";
33
+ registerExactAvmScheme(client, { signer });
34
+
35
+ // Server
36
+ import { registerExactAvmScheme } from "@x402-avm/avm/exact/server";
37
+ registerExactAvmScheme(server);
38
+
39
+ // Facilitator
40
+ import { registerExactAvmScheme } from "@x402-avm/avm/exact/facilitator";
41
+ registerExactAvmScheme(facilitator, { signer, networks: ALGORAND_TESTNET_CAIP2 });
42
+ ```
43
+
44
+ ### TypeScript algosdk Encoding
45
+
46
+ TypeScript algosdk works with raw `Uint8Array` directly — no conversion needed. This matches the `@txnlab/use-wallet` ecosystem standard. Encoding/decoding to/from base64 happens only at protocol boundaries (PAYMENT-SIGNATURE header serialization).
47
+
48
+ ## Reference Guide
49
+
50
+ Navigate to the appropriate reference based on your task. Each topic has three files:
51
+ - **`{name}.md`** — Step-by-step implementation guide
52
+ - **`{name}-reference.md`** — API details and type signatures
53
+ - **`{name}-examples.md`** — Complete, runnable code samples
54
+
55
+ ### Explaining x402 for TypeScript
56
+
57
+ Understand @x402-avm/* TypeScript package structure, signer interfaces (ClientAvmSigner, FacilitatorAvmSigner), registration patterns, builder patterns, constants, and utilities.
58
+
59
+ - [explain-algorand-x402-typescript.md](./references/explain-algorand-x402-typescript.md) — Package ecosystem explanation
60
+ - [explain-algorand-x402-typescript-reference.md](./references/explain-algorand-x402-typescript-reference.md) — API reference for @x402-avm/* packages
61
+ - [explain-algorand-x402-typescript-examples.md](./references/explain-algorand-x402-typescript-examples.md) — TypeScript pattern examples
62
+
63
+ ### Building Clients
64
+
65
+ Build HTTP clients with Fetch or Axios that automatically handle 402 payments. Covers wrapFetchWithPayment, wrapAxiosWithPayment, ClientAvmSigner for browser wallets or Node.js private keys.
66
+
67
+ - [create-typescript-x402-client.md](./references/create-typescript-x402-client.md) — Client creation guide
68
+ - [create-typescript-x402-client-reference.md](./references/create-typescript-x402-client-reference.md) — Fetch/Axios API reference
69
+ - [create-typescript-x402-client-examples.md](./references/create-typescript-x402-client-examples.md) — Client code examples
70
+
71
+ ### Building Servers
72
+
73
+ Build payment-protected servers with Express.js or Hono middleware. Covers route pricing, multi-network support (AVM+EVM+SVM), 402 responses, and dynamic pricing.
74
+
75
+ - [create-typescript-x402-server.md](./references/create-typescript-x402-server.md) — Server creation guide
76
+ - [create-typescript-x402-server-reference.md](./references/create-typescript-x402-server-reference.md) — Express/Hono middleware API reference
77
+ - [create-typescript-x402-server-examples.md](./references/create-typescript-x402-server-examples.md) — Server code examples
78
+
79
+ ### Building Next.js Apps
80
+
81
+ Build fullstack Next.js apps with x402 payment protection using paymentProxy and withX402. Covers App Router integration, middleware-level protection, and per-endpoint control.
82
+
83
+ - [create-typescript-x402-nextjs.md](./references/create-typescript-x402-nextjs.md) — Next.js integration guide
84
+ - [create-typescript-x402-nextjs-reference.md](./references/create-typescript-x402-nextjs-reference.md) — Next.js API reference
85
+ - [create-typescript-x402-nextjs-examples.md](./references/create-typescript-x402-nextjs-examples.md) — Next.js code examples
86
+
87
+ ### Building Facilitators and Bazaar Discovery
88
+
89
+ Build facilitator services that verify and settle Algorand payments on-chain. Covers FacilitatorAvmSigner, Express.js facilitator servers, and Bazaar discovery extension for API cataloging (bazaarResourceServerExtension, withBazaar, declare_discovery_extension on servers).
90
+
91
+ - [create-typescript-x402-facilitator.md](./references/create-typescript-x402-facilitator.md) — Facilitator creation guide (includes Bazaar setup in Step 5)
92
+ - [create-typescript-x402-facilitator-reference.md](./references/create-typescript-x402-facilitator-reference.md) — Facilitator + Bazaar API reference
93
+ - [create-typescript-x402-facilitator-examples.md](./references/create-typescript-x402-facilitator-examples.md) — Facilitator + Bazaar code examples
94
+
95
+ ### Building Paywalls
96
+
97
+ Build browser paywall UIs with server-side middleware and client-side wallet integration (Pera, Defly, Lute). Covers PaywallBuilder, avmPaywall, multi-network paywalls.
98
+
99
+ - [create-typescript-x402-paywall.md](./references/create-typescript-x402-paywall.md) — Paywall creation guide
100
+ - [create-typescript-x402-paywall-reference.md](./references/create-typescript-x402-paywall-reference.md) — Paywall API reference
101
+ - [create-typescript-x402-paywall-examples.md](./references/create-typescript-x402-paywall-examples.md) — Paywall code examples
102
+
103
+ ### Low-Level SDK Usage
104
+
105
+ Use @x402-avm/core and @x402-avm/avm packages directly for custom integrations. Covers payment policies, AVM signer interfaces, transaction groups, fee abstraction, and low-level primitives.
106
+
107
+ - [use-typescript-x402-core-avm.md](./references/use-typescript-x402-core-avm.md) — Core SDK usage guide
108
+ - [use-typescript-x402-core-avm-reference.md](./references/use-typescript-x402-core-avm-reference.md) — Core/AVM API reference
109
+ - [use-typescript-x402-core-avm-examples.md](./references/use-typescript-x402-core-avm-examples.md) — Core SDK code examples
110
+
111
+ ## TypeScript Package Quick Reference
112
+
113
+ | Package | Purpose |
114
+ | ------- | ------- |
115
+ | `@x402-avm/fetch` | Wrap fetch with automatic 402 payment handling |
116
+ | `@x402-avm/axios` | Wrap axios with automatic 402 payment handling |
117
+ | `@x402-avm/express` | Express.js payment middleware |
118
+ | `@x402-avm/hono` | Hono payment middleware |
119
+ | `@x402-avm/next` | Next.js payment middleware and route wrappers |
120
+ | `@x402-avm/paywall` | Browser paywall UI components |
121
+ | `@x402-avm/core` | Core protocol primitives (client, server, facilitator) |
122
+ | `@x402-avm/avm` | AVM mechanism (signers, transaction builders, constants) |
123
+
124
+ ## How to Use This Skill
125
+
126
+ 1. **Start here** to understand which reference you need
127
+ 2. **Read the `{name}.md`** file for step-by-step implementation guidance
128
+ 3. **Consult `{name}-reference.md`** for API details
129
+ 4. **Use `{name}-examples.md`** for complete, runnable code samples