@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,56 @@
|
|
|
1
|
+
# Troubleshoot Errors (TypeScript)
|
|
2
|
+
|
|
3
|
+
Diagnose and resolve common Algorand development errors when working with TypeScript and AlgoKit Utils TypeScript.
|
|
4
|
+
|
|
5
|
+
## Error References
|
|
6
|
+
|
|
7
|
+
| Category | Description | Reference |
|
|
8
|
+
|----------|-------------|-----------|
|
|
9
|
+
| Contract Errors | Assert failures, opcode budget, ABI issues, state errors | [troubleshoot-errors-contract.md](./troubleshoot-errors-contract.md) |
|
|
10
|
+
| Transaction Errors | Overspend, invalid params, group issues, asset/account errors | [troubleshoot-errors-transaction.md](./troubleshoot-errors-transaction.md) |
|
|
11
|
+
|
|
12
|
+
## TypeScript Debugging Quick Start
|
|
13
|
+
|
|
14
|
+
### Enable Debug Logging
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
import { Config } from '@algorandfoundation/algokit-utils'
|
|
18
|
+
Config.configure({ debug: true })
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Simulate with Execution Trace
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
// Simulate to get execution trace before sending
|
|
25
|
+
const result = await algorand.newGroup()
|
|
26
|
+
.addAppCallMethodCall(params)
|
|
27
|
+
.simulate({ execTraceConfig: { enable: true } })
|
|
28
|
+
|
|
29
|
+
console.log(result.simulateResponse.txnGroups[0].txnResults[0].execTrace)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Catch and Inspect Errors
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
try {
|
|
36
|
+
await appClient.send.myMethod({ args: { value: 0 } })
|
|
37
|
+
} catch (e) {
|
|
38
|
+
// AlgoKit Utils automatically includes source-mapped error info
|
|
39
|
+
// Error includes: "assert failed at contracts/my_contract.py:45"
|
|
40
|
+
console.error(e)
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Check Transaction Status
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
// Check pending transaction
|
|
48
|
+
const pending = await algorand.client.algod.pendingTransactionInformation(txId).do()
|
|
49
|
+
console.log('Pool error:', pending.poolError)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## How to Proceed
|
|
53
|
+
|
|
54
|
+
1. **Find your error** in the contract or transaction error references
|
|
55
|
+
2. **Understand the cause** from the explanation
|
|
56
|
+
3. **Apply the TypeScript fix** from the code examples
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
# AlgorandClient (TypeScript)
|
|
2
|
+
|
|
3
|
+
The main entry point for interacting with Algorand in TypeScript applications.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @algorandfoundation/algokit-utils
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Creating an AlgorandClient
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { AlgorandClient } from '@algorandfoundation/algokit-utils'
|
|
15
|
+
|
|
16
|
+
// From environment variables (recommended for production)
|
|
17
|
+
const algorand = AlgorandClient.fromEnvironment()
|
|
18
|
+
|
|
19
|
+
// Default LocalNet configuration
|
|
20
|
+
const algorand = AlgorandClient.defaultLocalNet()
|
|
21
|
+
|
|
22
|
+
// TestNet using AlgoNode free tier
|
|
23
|
+
const algorand = AlgorandClient.testNet()
|
|
24
|
+
|
|
25
|
+
// MainNet using AlgoNode free tier
|
|
26
|
+
const algorand = AlgorandClient.mainNet()
|
|
27
|
+
|
|
28
|
+
// From existing clients
|
|
29
|
+
const algorand = AlgorandClient.fromClients({ algod, indexer, kmd })
|
|
30
|
+
|
|
31
|
+
// From custom configuration
|
|
32
|
+
const algorand = AlgorandClient.fromConfig({
|
|
33
|
+
algodConfig: {
|
|
34
|
+
server: 'http://localhost',
|
|
35
|
+
port: '4001',
|
|
36
|
+
token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Accessing SDK Clients
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
const algodClient = algorand.client.algod
|
|
45
|
+
const indexerClient = algorand.client.indexer
|
|
46
|
+
const kmdClient = algorand.client.kmd
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Account Management
|
|
50
|
+
|
|
51
|
+
### Getting Accounts
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
// From environment variable (DEPLOYER_MNEMONIC)
|
|
55
|
+
const deployer = await algorand.account.fromEnvironment('DEPLOYER')
|
|
56
|
+
|
|
57
|
+
// Random account (for testing)
|
|
58
|
+
const random = algorand.account.random()
|
|
59
|
+
|
|
60
|
+
// From mnemonic
|
|
61
|
+
const account = algorand.account.fromMnemonic('abandon abandon...')
|
|
62
|
+
|
|
63
|
+
// From KMD (LocalNet)
|
|
64
|
+
const kmdAccount = await algorand.account.fromKmd('wallet-name', 'password')
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Registering Signers
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
// Register a signer for automatic signing
|
|
71
|
+
algorand.setSignerFromAccount(account)
|
|
72
|
+
|
|
73
|
+
// Set default signer for all transactions
|
|
74
|
+
algorand.setDefaultSigner(account.signer)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Sending Transactions
|
|
78
|
+
|
|
79
|
+
### Single Transactions
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { algo } from '@algorandfoundation/algokit-utils'
|
|
83
|
+
|
|
84
|
+
// Payment
|
|
85
|
+
const result = await algorand.send.payment({
|
|
86
|
+
sender: 'SENDERADDRESS',
|
|
87
|
+
receiver: 'RECEIVERADDRESS',
|
|
88
|
+
amount: algo(1),
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
// Asset transfer
|
|
92
|
+
await algorand.send.assetTransfer({
|
|
93
|
+
sender: 'SENDERADDRESS',
|
|
94
|
+
receiver: 'RECEIVERADDRESS',
|
|
95
|
+
assetId: 12345n,
|
|
96
|
+
amount: 100n,
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
// Asset opt-in
|
|
100
|
+
await algorand.send.assetOptIn({
|
|
101
|
+
sender: 'SENDERADDRESS',
|
|
102
|
+
assetId: 12345n,
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
// Asset create
|
|
106
|
+
const createResult = await algorand.send.assetCreate({
|
|
107
|
+
sender: 'SENDERADDRESS',
|
|
108
|
+
total: 1000000n,
|
|
109
|
+
decimals: 6,
|
|
110
|
+
assetName: 'My Token',
|
|
111
|
+
unitName: 'MTK',
|
|
112
|
+
})
|
|
113
|
+
const assetId = createResult.assetId
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Transaction Groups
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
const result = await algorand
|
|
120
|
+
.newGroup()
|
|
121
|
+
.addPayment({
|
|
122
|
+
sender: 'SENDERADDRESS',
|
|
123
|
+
receiver: 'RECEIVERADDRESS',
|
|
124
|
+
amount: algo(1),
|
|
125
|
+
})
|
|
126
|
+
.addAssetOptIn({
|
|
127
|
+
sender: 'SENDERADDRESS',
|
|
128
|
+
assetId: 12345n,
|
|
129
|
+
})
|
|
130
|
+
.send()
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Creating Transactions (Without Sending)
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
const payment = await algorand.createTransaction.payment({
|
|
137
|
+
sender: 'SENDERADDRESS',
|
|
138
|
+
receiver: 'RECEIVERADDRESS',
|
|
139
|
+
amount: algo(1),
|
|
140
|
+
})
|
|
141
|
+
// payment is an unsigned algosdk.Transaction
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Common Transaction Parameters
|
|
145
|
+
|
|
146
|
+
All transactions support these common parameters:
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
await algorand.send.payment({
|
|
150
|
+
sender: 'SENDERADDRESS',
|
|
151
|
+
receiver: 'RECEIVERADDRESS',
|
|
152
|
+
amount: algo(1),
|
|
153
|
+
|
|
154
|
+
// Optional parameters
|
|
155
|
+
note: 'My note',
|
|
156
|
+
lease: 'unique-lease-id',
|
|
157
|
+
rekeyTo: 'NEWADDRESS',
|
|
158
|
+
|
|
159
|
+
// Fee management
|
|
160
|
+
staticFee: algo(0.001),
|
|
161
|
+
extraFee: algo(0.001), // For covering inner txn fees
|
|
162
|
+
maxFee: algo(0.01),
|
|
163
|
+
|
|
164
|
+
// Validity
|
|
165
|
+
validityWindow: 1000,
|
|
166
|
+
firstValidRound: 12345n,
|
|
167
|
+
lastValidRound: 12445n,
|
|
168
|
+
})
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## App Calls
|
|
172
|
+
|
|
173
|
+
### Using Typed App Clients (Recommended)
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
// Get typed factory from generated client
|
|
177
|
+
const factory = algorand.client.getTypedAppFactory(MyContractFactory)
|
|
178
|
+
|
|
179
|
+
// Deploy
|
|
180
|
+
const { appClient, result } = await factory.deploy({
|
|
181
|
+
sender: deployer.addr,
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
// Call methods
|
|
185
|
+
const response = await appClient.send.myMethod({
|
|
186
|
+
sender: deployer.addr,
|
|
187
|
+
args: { param1: 'value' },
|
|
188
|
+
})
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Generic App Calls
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
await algorand.send.appCallMethodCall({
|
|
195
|
+
sender: 'SENDERADDRESS',
|
|
196
|
+
appId: 12345n,
|
|
197
|
+
method: algosdk.ABIMethod.fromSignature('hello(string)string'),
|
|
198
|
+
args: ['World'],
|
|
199
|
+
})
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Send Parameters
|
|
203
|
+
|
|
204
|
+
Control execution behavior when sending:
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
await algorand.send.payment(
|
|
208
|
+
{
|
|
209
|
+
sender: 'SENDERADDRESS',
|
|
210
|
+
receiver: 'RECEIVERADDRESS',
|
|
211
|
+
amount: algo(1),
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
// Wait for confirmation
|
|
215
|
+
maxRoundsToWaitForConfirmation: 5,
|
|
216
|
+
|
|
217
|
+
// Suppress logging
|
|
218
|
+
suppressLog: true,
|
|
219
|
+
|
|
220
|
+
// Auto-populate app call resources
|
|
221
|
+
populateAppCallResources: true,
|
|
222
|
+
|
|
223
|
+
// Auto-calculate inner txn fees
|
|
224
|
+
coverAppCallInnerTransactionFees: true,
|
|
225
|
+
}
|
|
226
|
+
)
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Amount Helpers
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
import { algo, microAlgo } from '@algorandfoundation/algokit-utils'
|
|
233
|
+
|
|
234
|
+
algo(1) // 1 Algo = 1,000,000 microAlgo
|
|
235
|
+
algo(0.5) // 0.5 Algo = 500,000 microAlgo
|
|
236
|
+
microAlgo(1000) // 1000 microAlgo
|
|
237
|
+
|
|
238
|
+
// Extension method syntax (alternative)
|
|
239
|
+
(1).algo() // 1 Algo = 1,000,000 microAlgo
|
|
240
|
+
(100).microAlgo() // 100 microAlgo
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Testing with algorandFixture
|
|
244
|
+
|
|
245
|
+
For testing, use `algorandFixture` to manage LocalNet lifecycle:
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
import { algorandFixture, AlgorandFixtureConfig } from '@algorandfoundation/algokit-utils/testing'
|
|
249
|
+
import { Config } from '@algorandfoundation/algokit-utils'
|
|
250
|
+
|
|
251
|
+
// Basic setup
|
|
252
|
+
const localnet = algorandFixture()
|
|
253
|
+
|
|
254
|
+
// With custom configuration
|
|
255
|
+
const localnet = algorandFixture({
|
|
256
|
+
testAccountFunding: algo(100), // Fund test accounts with 100 Algo
|
|
257
|
+
algodConfig: {
|
|
258
|
+
server: 'http://localhost',
|
|
259
|
+
port: '4001',
|
|
260
|
+
token: 'aaaa...',
|
|
261
|
+
},
|
|
262
|
+
} satisfies AlgorandFixtureConfig)
|
|
263
|
+
|
|
264
|
+
// In tests
|
|
265
|
+
beforeAll(() => {
|
|
266
|
+
Config.configure({ debug: true })
|
|
267
|
+
})
|
|
268
|
+
beforeEach(localnet.newScope, 10_000) // 10s timeout for LocalNet setup
|
|
269
|
+
|
|
270
|
+
// Access algorand client
|
|
271
|
+
const { algorand, testAccount } = localnet.context
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### Log Capture Fixture
|
|
275
|
+
|
|
276
|
+
Use `algoKitLogCaptureFixture` to capture and verify logs in tests:
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
import { algoKitLogCaptureFixture } from '@algorandfoundation/algokit-utils/testing'
|
|
280
|
+
|
|
281
|
+
const logs = algoKitLogCaptureFixture()
|
|
282
|
+
|
|
283
|
+
beforeEach(logs.beforeEach)
|
|
284
|
+
afterEach(logs.afterEach)
|
|
285
|
+
|
|
286
|
+
test('should log transaction', async () => {
|
|
287
|
+
// ... perform operations
|
|
288
|
+
expect(logs.testLogger.getLogSnapshot()).toMatchInlineSnapshot()
|
|
289
|
+
})
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## Common Patterns
|
|
293
|
+
|
|
294
|
+
### Fund an Account
|
|
295
|
+
|
|
296
|
+
```typescript
|
|
297
|
+
await algorand.send.payment({
|
|
298
|
+
sender: funderAccount.addr,
|
|
299
|
+
receiver: newAccount.addr,
|
|
300
|
+
amount: algo(10),
|
|
301
|
+
})
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
### Create and Fund in One Group
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
const newAccount = algorand.account.random()
|
|
308
|
+
|
|
309
|
+
await algorand
|
|
310
|
+
.newGroup()
|
|
311
|
+
.addPayment({
|
|
312
|
+
sender: funder.addr,
|
|
313
|
+
receiver: newAccount.addr,
|
|
314
|
+
amount: algo(1),
|
|
315
|
+
})
|
|
316
|
+
.addAssetOptIn({
|
|
317
|
+
sender: newAccount.addr,
|
|
318
|
+
assetId: 12345n,
|
|
319
|
+
})
|
|
320
|
+
.send()
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
### Deploy and Fund Contract
|
|
324
|
+
|
|
325
|
+
```typescript
|
|
326
|
+
const factory = algorand.client.getTypedAppFactory(MyContractFactory)
|
|
327
|
+
const { appClient } = await factory.deploy({ sender: deployer.addr })
|
|
328
|
+
|
|
329
|
+
// Fund the app account for box storage
|
|
330
|
+
await algorand.send.payment({
|
|
331
|
+
sender: deployer.addr,
|
|
332
|
+
receiver: appClient.appAddress,
|
|
333
|
+
amount: algo(1),
|
|
334
|
+
})
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
## References
|
|
338
|
+
|
|
339
|
+
- [AlgoKit Utils TS Overview](https://dev.algorand.co/algokit/utils/typescript/overview/)
|
|
340
|
+
- [AlgorandClient API](https://dev.algorand.co/reference/algokit-utils-ts/api/classes/types_algorand_clientalgorandclient/)
|
|
341
|
+
- [Transaction Composer](https://dev.algorand.co/algokit/utils/typescript/transaction-composer/)
|
|
342
|
+
- [Account Management](https://dev.algorand.co/algokit/utils/typescript/account/)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# AlgoKit Utils (TypeScript)
|
|
2
|
+
|
|
3
|
+
AlgoKit Utils for TypeScript is the primary library for building Algorand applications in TypeScript/JavaScript. It provides a high-level, ergonomic interface via the `AlgorandClient` class, which is the single entry point for interacting with the Algorand network -- sending transactions, managing accounts, deploying smart contracts, and more.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @algorandfoundation/algokit-utils
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
### 1. Create an AlgorandClient
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { AlgorandClient } from '@algorandfoundation/algokit-utils'
|
|
17
|
+
|
|
18
|
+
// Connect to LocalNet (development)
|
|
19
|
+
const algorand = AlgorandClient.defaultLocalNet()
|
|
20
|
+
|
|
21
|
+
// Connect to TestNet
|
|
22
|
+
const algorand = AlgorandClient.testNet()
|
|
23
|
+
|
|
24
|
+
// Connect to MainNet
|
|
25
|
+
const algorand = AlgorandClient.mainNet()
|
|
26
|
+
|
|
27
|
+
// From environment variables (recommended for production)
|
|
28
|
+
const algorand = AlgorandClient.fromEnvironment()
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### 2. Get and Register an Account
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
// Get a random account (testing)
|
|
35
|
+
const account = algorand.account.random()
|
|
36
|
+
|
|
37
|
+
// From environment variable (e.g. DEPLOYER_MNEMONIC)
|
|
38
|
+
const deployer = await algorand.account.fromEnvironment('DEPLOYER')
|
|
39
|
+
|
|
40
|
+
// Register the signer so transactions are automatically signed
|
|
41
|
+
algorand.setSignerFromAccount(account)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 3. Send a Transaction
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { algo } from '@algorandfoundation/algokit-utils'
|
|
48
|
+
|
|
49
|
+
const result = await algorand.send.payment({
|
|
50
|
+
sender: account.addr,
|
|
51
|
+
receiver: 'RECEIVERADDRESS',
|
|
52
|
+
amount: algo(1),
|
|
53
|
+
})
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Key Rules
|
|
57
|
+
|
|
58
|
+
1. **Always use `AlgorandClient`** as the single entry point. Do not instantiate lower-level SDK clients directly.
|
|
59
|
+
2. **Use `AlgorandClient.fromEnvironment()`** for production deployments and CI/CD pipelines.
|
|
60
|
+
3. **Register signers** with `algorand.setSignerFromAccount(account)` before sending transactions so signing is handled automatically.
|
|
61
|
+
4. **Use the `algo()` and `microAlgo()` helpers** for amounts instead of raw numbers to avoid unit conversion errors.
|
|
62
|
+
|
|
63
|
+
## Reference
|
|
64
|
+
|
|
65
|
+
For the full AlgorandClient API covering client creation, account management, transaction sending, app calls, transaction groups, amount helpers, testing fixtures, and common patterns:
|
|
66
|
+
|
|
67
|
+
[AlgorandClient Reference](./use-algokit-utils-reference.md)
|
|
68
|
+
|
|
69
|
+
## External Links
|
|
70
|
+
|
|
71
|
+
- [AlgoKit Utils TS Overview](https://dev.algorand.co/algokit/utils/typescript/overview/)
|
|
72
|
+
- [AlgorandClient API Reference](https://dev.algorand.co/reference/algokit-utils-ts/api/classes/types_algorand_clientalgorandclient/)
|
|
73
|
+
- [Transaction Composer](https://dev.algorand.co/algokit/utils/typescript/transaction-composer/)
|
|
74
|
+
- [Account Management](https://dev.algorand.co/algokit/utils/typescript/account/)
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: algorand-x402-python
|
|
3
|
+
description: Comprehensive guide for building x402 HTTP-native payment applications on Algorand using Python. This is the parent skill that aggregates all Python x402 sub-skills. Use when working with x402 payments in Python, building clients, servers, facilitators, or Bazaar discovery with Algorand x402, or when explaining x402 concepts to Python developers. Strong triggers include "x402 Python", "x402 Algorand Python", "x402-avm Python", "payment protocol Python", "402 payment Python", "x402 client httpx requests", "x402 server FastAPI Flask", "x402 facilitator Python", "x402 Bazaar discovery", "x402 core avm Python", "explain x402 Python", "teach x402".
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# x402 on Algorand - Python
|
|
7
|
+
|
|
8
|
+
This is the aggregated parent skill for all x402 HTTP-native payment protocol skills targeting Python. Use the reference files below to find detailed guidance for each component.
|
|
9
|
+
|
|
10
|
+
## Python Quick Start
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
# Minimal AVM support
|
|
14
|
+
pip install x402-avm[avm]
|
|
15
|
+
|
|
16
|
+
# Server frameworks (pick one)
|
|
17
|
+
pip install x402-avm[avm,fastapi]
|
|
18
|
+
pip install x402-avm[avm,flask]
|
|
19
|
+
|
|
20
|
+
# HTTP clients (pick one)
|
|
21
|
+
pip install x402-avm[avm,httpx]
|
|
22
|
+
pip install x402-avm[avm,requests]
|
|
23
|
+
|
|
24
|
+
# Everything
|
|
25
|
+
pip install x402-avm[all]
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Register AVM Scheme
|
|
29
|
+
|
|
30
|
+
Every component registers the AVM exact scheme unconditionally — no environment variable guards:
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
# Client
|
|
34
|
+
from x402_avm.mechanisms.avm.exact.client import register_exact_avm_scheme
|
|
35
|
+
register_exact_avm_scheme(client, signer=my_signer)
|
|
36
|
+
|
|
37
|
+
# Server
|
|
38
|
+
from x402_avm.mechanisms.avm.exact.server import register_exact_avm_scheme
|
|
39
|
+
register_exact_avm_scheme(server)
|
|
40
|
+
|
|
41
|
+
# Facilitator
|
|
42
|
+
from x402_avm.mechanisms.avm.exact.facilitator import register_exact_avm_facilitator
|
|
43
|
+
register_exact_avm_facilitator(facilitator, signer=my_signer, networks=ALGORAND_TESTNET_CAIP2)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Python algosdk Encoding
|
|
47
|
+
|
|
48
|
+
Python algosdk's `msgpack_decode()` expects base64 strings, `msgpack_encode()` returns base64 strings. Boundary conversion: `msgpack_decode(base64.b64encode(raw_bytes).decode())` / `base64.b64decode(msgpack_encode(obj))`.
|
|
49
|
+
|
|
50
|
+
## Reference Guide
|
|
51
|
+
|
|
52
|
+
Navigate to the appropriate reference based on your task. Each topic has three files:
|
|
53
|
+
- **`{name}.md`** — Step-by-step implementation guide
|
|
54
|
+
- **`{name}-reference.md`** — API details and type signatures
|
|
55
|
+
- **`{name}-examples.md`** — Complete, runnable code samples
|
|
56
|
+
|
|
57
|
+
### Explaining x402 for Python
|
|
58
|
+
|
|
59
|
+
Understand x402-avm Python package structure, extras installation ([avm], [fastapi], [flask], [httpx], [requests], [all]), signer protocols, async vs sync variants, and algosdk encoding boundaries.
|
|
60
|
+
|
|
61
|
+
- [explain-algorand-x402-python.md](./references/explain-algorand-x402-python.md) — Package ecosystem explanation
|
|
62
|
+
- [explain-algorand-x402-python-reference.md](./references/explain-algorand-x402-python-reference.md) — API reference for x402-avm packages
|
|
63
|
+
- [explain-algorand-x402-python-examples.md](./references/explain-algorand-x402-python-examples.md) — Python pattern examples
|
|
64
|
+
|
|
65
|
+
### Building Clients
|
|
66
|
+
|
|
67
|
+
Build HTTP clients with httpx (async) or requests (sync) that automatically handle 402 payments. Covers wrapHttpxWithPayment, wrapRequestsWithPayment, ClientAvmSigner for payment signing.
|
|
68
|
+
|
|
69
|
+
- [create-python-x402-client.md](./references/create-python-x402-client.md) — Client creation guide
|
|
70
|
+
- [create-python-x402-client-reference.md](./references/create-python-x402-client-reference.md) — httpx/requests API reference
|
|
71
|
+
- [create-python-x402-client-examples.md](./references/create-python-x402-client-examples.md) — Client code examples
|
|
72
|
+
|
|
73
|
+
### Building Servers
|
|
74
|
+
|
|
75
|
+
Build payment-protected servers with FastAPI (async) or Flask (sync) middleware. Covers route pricing, PaymentMiddlewareASGI, Flask PaymentMiddleware, and multi-network support.
|
|
76
|
+
|
|
77
|
+
- [create-python-x402-server.md](./references/create-python-x402-server.md) — Server creation guide
|
|
78
|
+
- [create-python-x402-server-reference.md](./references/create-python-x402-server-reference.md) — FastAPI/Flask middleware API reference
|
|
79
|
+
- [create-python-x402-server-examples.md](./references/create-python-x402-server-examples.md) — Server code examples
|
|
80
|
+
|
|
81
|
+
### Building Facilitators and Bazaar Discovery
|
|
82
|
+
|
|
83
|
+
Build facilitator services that verify and settle Algorand payments on-chain. Covers FacilitatorAvmSigner protocol, register_exact_avm_facilitator, FastAPI facilitator endpoints (/verify, /settle, /supported), and Bazaar discovery extension for automatic cataloging and indexing of payment-gated APIs (declare_discovery_extension, extract_discovery_info, bazaar_resource_server_extension).
|
|
84
|
+
|
|
85
|
+
- [create-python-x402-facilitator.md](./references/create-python-x402-facilitator.md) — Facilitator creation guide (includes Bazaar setup in Steps 6-10)
|
|
86
|
+
- [create-python-x402-facilitator-reference.md](./references/create-python-x402-facilitator-reference.md) — Facilitator + Bazaar API reference
|
|
87
|
+
- [create-python-x402-facilitator-examples.md](./references/create-python-x402-facilitator-examples.md) — Facilitator + Bazaar code examples
|
|
88
|
+
|
|
89
|
+
### Low-Level SDK Usage
|
|
90
|
+
|
|
91
|
+
Use x402-avm core components and AVM mechanism directly for custom integrations. Covers x402Client, x402ResourceServer, x402Facilitator, AVM signer protocols, constants, utilities, transaction encoding, and fee abstraction.
|
|
92
|
+
|
|
93
|
+
- [use-python-x402-core-avm.md](./references/use-python-x402-core-avm.md) — Core SDK usage guide
|
|
94
|
+
- [use-python-x402-core-avm-reference.md](./references/use-python-x402-core-avm-reference.md) — Core/AVM API reference
|
|
95
|
+
- [use-python-x402-core-avm-examples.md](./references/use-python-x402-core-avm-examples.md) — Core SDK code examples
|
|
96
|
+
|
|
97
|
+
## Python Package Quick Reference
|
|
98
|
+
|
|
99
|
+
| Install Extra | Purpose |
|
|
100
|
+
| ------------- | ------- |
|
|
101
|
+
| `x402-avm[httpx]` | Async HTTP client with automatic 402 payment handling |
|
|
102
|
+
| `x402-avm[requests]` | Sync HTTP client with automatic 402 payment handling |
|
|
103
|
+
| `x402-avm[fastapi]` | FastAPI async payment middleware |
|
|
104
|
+
| `x402-avm[flask]` | Flask sync payment middleware |
|
|
105
|
+
| `x402-avm[avm]` | Core AVM mechanism (signers, transaction builders, constants) |
|
|
106
|
+
| `x402-avm[all]` | All extras combined |
|
|
107
|
+
|
|
108
|
+
## How to Use This Skill
|
|
109
|
+
|
|
110
|
+
1. **Start here** to understand which reference you need
|
|
111
|
+
2. **Read the `{name}.md`** file for step-by-step implementation guidance
|
|
112
|
+
3. **Consult `{name}-reference.md`** for API details
|
|
113
|
+
4. **Use `{name}-examples.md`** for complete, runnable code samples
|