@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,74 @@
|
|
|
1
|
+
# Building Smart Contracts (TypeScript)
|
|
2
|
+
|
|
3
|
+
Create Algorand smart contracts using Algorand TypeScript (PuyaTs) -- a statically-typed TypeScript subset compiled to TEAL bytecode by the Puya compiler.
|
|
4
|
+
|
|
5
|
+
## Core Workflow
|
|
6
|
+
|
|
7
|
+
1. **Search documentation** for concepts and best practices
|
|
8
|
+
2. **Retrieve canonical TypeScript examples** from priority repositories
|
|
9
|
+
3. **Generate code** following Algorand TypeScript syntax rules
|
|
10
|
+
4. **Include integration tests** using generated clients
|
|
11
|
+
5. **Build and test** with AlgoKit commands
|
|
12
|
+
|
|
13
|
+
## TypeScript Repository Priorities
|
|
14
|
+
|
|
15
|
+
When retrieving examples, search these repositories in order:
|
|
16
|
+
|
|
17
|
+
1. **`algorandfoundation/devportal-code-examples`**
|
|
18
|
+
- Path: `projects/typescript-examples/contracts/`
|
|
19
|
+
- Best source for common patterns (BoxStorage, state management, etc.)
|
|
20
|
+
- Always include corresponding test files
|
|
21
|
+
|
|
22
|
+
2. **`algorandfoundation/puya-ts`**
|
|
23
|
+
- Path: `examples/`
|
|
24
|
+
- Examples: `hello_world_arc4/`, `voting/`, `amm/`
|
|
25
|
+
- Best for compiler-level patterns and advanced features
|
|
26
|
+
|
|
27
|
+
3. **`algorandfoundation/algokit-typescript-template`**
|
|
28
|
+
- Project scaffolding and structure reference
|
|
29
|
+
- Integration test patterns
|
|
30
|
+
|
|
31
|
+
## TypeScript-Specific Patterns
|
|
32
|
+
|
|
33
|
+
### File Extension
|
|
34
|
+
All Algorand TypeScript contract files must use the `.algo.ts` extension:
|
|
35
|
+
```
|
|
36
|
+
contracts/MyContract.algo.ts
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Clone Pattern
|
|
40
|
+
When working with mutable ARC-4 types, use `clone()` to avoid aliasing issues:
|
|
41
|
+
```typescript
|
|
42
|
+
const copy = original.clone()
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Key Syntax Rules
|
|
46
|
+
|
|
47
|
+
- Contracts extend `Contract` class from `@algorandfoundation/algorand-typescript`
|
|
48
|
+
- Use `@abimethod()` decorator for ABI-callable methods
|
|
49
|
+
- Use `GlobalState<T>` and `LocalState<T>` for on-chain storage
|
|
50
|
+
- Use `itxn` namespace for inner transactions
|
|
51
|
+
- Always set `fee: 0` on inner transactions (fee pooling)
|
|
52
|
+
|
|
53
|
+
For full TypeScript syntax rules, see the `algorand-typescript-syntax` topic and its detailed references.
|
|
54
|
+
|
|
55
|
+
## Build and Test
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
algokit project run build # Compile contracts
|
|
59
|
+
algokit project run test # Run tests
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Important Rules
|
|
63
|
+
|
|
64
|
+
- **NEVER use PyTEAL or Beaker** -- these are legacy
|
|
65
|
+
- **NEVER write raw TEAL** -- always use Algorand TypeScript
|
|
66
|
+
- **NEVER import external libraries** into contract code
|
|
67
|
+
- **Always search docs first** before writing code
|
|
68
|
+
- **Always retrieve TypeScript examples** from priority repositories
|
|
69
|
+
|
|
70
|
+
## References
|
|
71
|
+
|
|
72
|
+
- [TypeScript Repository and Pattern Reference](./build-smart-contracts-reference.md)
|
|
73
|
+
- [Algorand TypeScript Syntax](./algorand-typescript-syntax.md)
|
|
74
|
+
- [TypeScript Syntax Reference](./algorand-typescript-syntax-reference.md)
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
# Calling Smart Contracts Reference
|
|
2
|
+
|
|
3
|
+
CLI commands and TypeScript client patterns for contract interaction.
|
|
4
|
+
|
|
5
|
+
## CLI Commands
|
|
6
|
+
|
|
7
|
+
### Build Contract
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
algokit project run build
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Compiles contracts and generates:
|
|
14
|
+
- ARC-56 app spec (`*.arc56.json`)
|
|
15
|
+
- TypeScript client (`client.ts`)
|
|
16
|
+
|
|
17
|
+
### Deploy Contract
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# To localnet
|
|
21
|
+
algokit project deploy localnet
|
|
22
|
+
|
|
23
|
+
# To testnet (requires funded account)
|
|
24
|
+
algokit project deploy testnet
|
|
25
|
+
|
|
26
|
+
# To mainnet
|
|
27
|
+
algokit project deploy mainnet
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Localnet Management
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# Start localnet
|
|
34
|
+
algokit localnet start
|
|
35
|
+
|
|
36
|
+
# Check status
|
|
37
|
+
algokit localnet status
|
|
38
|
+
|
|
39
|
+
# Reset (clears all data)
|
|
40
|
+
algokit localnet reset
|
|
41
|
+
|
|
42
|
+
# Stop
|
|
43
|
+
algokit localnet stop
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Run Custom Scripts
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# Run a TypeScript script
|
|
50
|
+
npx tsx scripts/my-script.ts
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## TypeScript Client Patterns
|
|
56
|
+
|
|
57
|
+
### Initialize AlgorandClient
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { AlgorandClient } from '@algorandfoundation/algokit-utils'
|
|
61
|
+
|
|
62
|
+
// From environment (reads ALGORAND_* env vars)
|
|
63
|
+
const algorand = AlgorandClient.fromEnvironment()
|
|
64
|
+
|
|
65
|
+
// Explicit localnet
|
|
66
|
+
const algorand = AlgorandClient.defaultLocalNet()
|
|
67
|
+
|
|
68
|
+
// Explicit testnet
|
|
69
|
+
const algorand = AlgorandClient.testNet()
|
|
70
|
+
|
|
71
|
+
// Explicit mainnet
|
|
72
|
+
const algorand = AlgorandClient.mainNet()
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Get Account
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
// From environment variable (e.g., DEPLOYER_MNEMONIC)
|
|
79
|
+
const account = await algorand.account.fromEnvironment('DEPLOYER')
|
|
80
|
+
|
|
81
|
+
// From mnemonic directly
|
|
82
|
+
const account = await algorand.account.fromMnemonic('word1 word2 ...')
|
|
83
|
+
|
|
84
|
+
// Localnet dispenser (auto-funded)
|
|
85
|
+
const dispenser = await algorand.account.localNetDispenser()
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Create Typed Client
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import { MyContractClient } from './artifacts/MyContract/client'
|
|
92
|
+
|
|
93
|
+
// By App ID (for existing deployment)
|
|
94
|
+
const client = algorand.client.getTypedAppClientById(MyContractClient, {
|
|
95
|
+
appId: BigInt(1234),
|
|
96
|
+
sender: account,
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
// By creator (finds latest deployment by creator address)
|
|
100
|
+
const client = await algorand.client.getTypedAppClientByCreatorAndName(MyContractClient, {
|
|
101
|
+
creatorAddress: account.addr,
|
|
102
|
+
sender: account,
|
|
103
|
+
})
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Call Methods
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
// No arguments, no return
|
|
110
|
+
await client.send.myMethod({})
|
|
111
|
+
|
|
112
|
+
// With arguments
|
|
113
|
+
await client.send.setValue({ args: { value: 42n } })
|
|
114
|
+
|
|
115
|
+
// With payment
|
|
116
|
+
await client.send.deposit({
|
|
117
|
+
args: { amount: 1_000_000n },
|
|
118
|
+
extraFee: AlgoAmount.MicroAlgos(1000),
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
// Get return value
|
|
122
|
+
const result = await client.send.getValue({})
|
|
123
|
+
console.log(result.return) // typed return value
|
|
124
|
+
|
|
125
|
+
// With version parameters (for versioned contracts)
|
|
126
|
+
await client.send.myMethod({
|
|
127
|
+
args: { value: 42n },
|
|
128
|
+
appVersion: '1.0.0', // Optional: specify expected app version
|
|
129
|
+
rejectVersion: '0.9.0', // Optional: reject if app is this version
|
|
130
|
+
})
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Read State
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
// Global state - all keys
|
|
137
|
+
const globalState = await client.state.global.getAll()
|
|
138
|
+
|
|
139
|
+
// Global state - specific typed key
|
|
140
|
+
const count = await client.state.global.count()
|
|
141
|
+
|
|
142
|
+
// Local state for an address
|
|
143
|
+
const localState = await client.state.local(address).getAll()
|
|
144
|
+
|
|
145
|
+
// Box storage
|
|
146
|
+
const boxValue = await client.state.box.myBox()
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Opt-In / Close-Out
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
// Opt-in with ABI method
|
|
153
|
+
await client.send.optIn.optIn({})
|
|
154
|
+
|
|
155
|
+
// Bare opt-in (no method call)
|
|
156
|
+
await client.send.optIn.bare({})
|
|
157
|
+
|
|
158
|
+
// Close-out with ABI method
|
|
159
|
+
await client.send.closeOut.closeOut({})
|
|
160
|
+
|
|
161
|
+
// Bare close-out
|
|
162
|
+
await client.send.closeOut.bare({})
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Delete Application
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
// With ABI method
|
|
169
|
+
await client.send.delete.deleteApplication({})
|
|
170
|
+
|
|
171
|
+
// Bare delete
|
|
172
|
+
await client.send.delete.bare({})
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## deploy-config.ts Pattern
|
|
178
|
+
|
|
179
|
+
The standard deployment configuration file:
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
// smart_contracts/deploy-config.ts
|
|
183
|
+
import { AlgorandClient } from '@algorandfoundation/algokit-utils'
|
|
184
|
+
import { MyContractClient } from './artifacts/MyContract/client'
|
|
185
|
+
|
|
186
|
+
export async function deploy() {
|
|
187
|
+
const algorand = AlgorandClient.fromEnvironment()
|
|
188
|
+
const deployer = await algorand.account.fromEnvironment('DEPLOYER')
|
|
189
|
+
|
|
190
|
+
const client = await algorand.client.getTypedAppClientByCreatorAndName(
|
|
191
|
+
MyContractClient,
|
|
192
|
+
{
|
|
193
|
+
creatorAddress: deployer.addr,
|
|
194
|
+
sender: deployer,
|
|
195
|
+
}
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
// Deploy or get existing
|
|
199
|
+
const app = await client.deploy({
|
|
200
|
+
onUpdate: 'update',
|
|
201
|
+
onSchemaBreak: 'replace',
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
console.log(`App ID: ${app.appId}`)
|
|
205
|
+
return app
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
## Error Troubleshooting
|
|
212
|
+
|
|
213
|
+
| Error | Cause | Solution |
|
|
214
|
+
|-------|-------|----------|
|
|
215
|
+
| "logic eval error" | Contract rejected call | Check method args, contract logic |
|
|
216
|
+
| "below min" | Insufficient funds | Fund the sender account |
|
|
217
|
+
| "not opted in" | Account hasn't opted in | Call opt-in first |
|
|
218
|
+
| "app does not exist" | Wrong App ID | Verify App ID from deployment |
|
|
219
|
+
| "network unreachable" | Localnet not running | `algokit localnet start` |
|
|
220
|
+
| "Cannot find module" | Client not generated | `algokit project run build` |
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
## Environment Variables
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
# Network selection
|
|
228
|
+
ALGORAND_NETWORK=localnet # or testnet, mainnet
|
|
229
|
+
|
|
230
|
+
# Account mnemonic (for testnet/mainnet)
|
|
231
|
+
DEPLOYER_MNEMONIC="word1 word2 word3 ..."
|
|
232
|
+
|
|
233
|
+
# Algod connection (usually auto-configured)
|
|
234
|
+
ALGOD_SERVER=http://localhost
|
|
235
|
+
ALGOD_PORT=4001
|
|
236
|
+
ALGOD_TOKEN=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
|
237
|
+
```
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
|
|
2
|
+
# Calling Smart Contracts
|
|
3
|
+
|
|
4
|
+
Deploy and interact with Algorand smart contracts using AlgoKit CLI and the generated TypeScript client.
|
|
5
|
+
|
|
6
|
+
## Overview / Core Workflow
|
|
7
|
+
|
|
8
|
+
1. Build the contract: `algokit project run build`
|
|
9
|
+
2. Deploy using CLI: `algokit project deploy localnet`
|
|
10
|
+
3. Write TypeScript scripts using the generated client
|
|
11
|
+
4. Run scripts: `npx tsx scripts/my-script.ts`
|
|
12
|
+
|
|
13
|
+
## How to proceed
|
|
14
|
+
|
|
15
|
+
### 1. Build the Contract
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
algokit project run build
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
This compiles your contract and generates:
|
|
22
|
+
- `artifacts/<ContractName>/<ContractName>.arc56.json` — ARC-56 app spec
|
|
23
|
+
- `artifacts/<ContractName>/client.ts` — Generated TypeScript client
|
|
24
|
+
|
|
25
|
+
### 2. Deploy to Localnet
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# Start localnet if not running
|
|
29
|
+
algokit localnet start
|
|
30
|
+
|
|
31
|
+
# Deploy (runs deploy-config.ts)
|
|
32
|
+
algokit project deploy localnet
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The deployment script (`smart_contracts/deploy-config.ts`) handles:
|
|
36
|
+
- Idempotent deployment (safe to re-run)
|
|
37
|
+
- App ID tracking
|
|
38
|
+
- Initial state setup
|
|
39
|
+
|
|
40
|
+
Note the App ID from the deployment output.
|
|
41
|
+
|
|
42
|
+
### 3. Interact Using Generated Client
|
|
43
|
+
|
|
44
|
+
Create scripts in your project to call contract methods. Example structure:
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
// scripts/call-contract.ts
|
|
48
|
+
import { AlgorandClient } from '@algorandfoundation/algokit-utils'
|
|
49
|
+
import { CounterClient } from '../smart_contracts/artifacts/Counter/client'
|
|
50
|
+
|
|
51
|
+
async function main() {
|
|
52
|
+
// Connect to localnet
|
|
53
|
+
const algorand = AlgorandClient.fromEnvironment()
|
|
54
|
+
|
|
55
|
+
// Get the default account (localnet dispenser)
|
|
56
|
+
const deployer = await algorand.account.fromEnvironment('DEPLOYER')
|
|
57
|
+
|
|
58
|
+
// Create client for deployed app
|
|
59
|
+
const client = algorand.client.getTypedAppClientById(CounterClient, {
|
|
60
|
+
appId: BigInt(1234), // Replace with actual App ID
|
|
61
|
+
sender: deployer,
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
// Call a method
|
|
65
|
+
const result = await client.send.increment({})
|
|
66
|
+
console.log('New count:', result.return)
|
|
67
|
+
|
|
68
|
+
// Read global state
|
|
69
|
+
const state = await client.state.global.getAll()
|
|
70
|
+
console.log('Global state:', state)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
main().catch(console.error)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Run with:
|
|
77
|
+
```bash
|
|
78
|
+
npx tsx scripts/call-contract.ts
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### 4. Common Operations
|
|
82
|
+
|
|
83
|
+
#### Call a Method
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
// No arguments
|
|
87
|
+
const result = await client.send.increment({})
|
|
88
|
+
|
|
89
|
+
// With arguments
|
|
90
|
+
const result = await client.send.setValue({ args: { value: 42n } })
|
|
91
|
+
|
|
92
|
+
// Access return value
|
|
93
|
+
console.log('Return:', result.return)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
#### Read Global State
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
// Get all global state
|
|
100
|
+
const state = await client.state.global.getAll()
|
|
101
|
+
|
|
102
|
+
// Get specific key (if typed in contract)
|
|
103
|
+
const count = await client.state.global.count()
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### Read Local State
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
// Get local state for an address
|
|
110
|
+
const localState = await client.state.local(address).getAll()
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
#### Opt-In to Application
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
// If contract has an opt_in method
|
|
117
|
+
await client.send.optIn.optIn({})
|
|
118
|
+
|
|
119
|
+
// Or use bare opt-in
|
|
120
|
+
await client.send.optIn.bare({})
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
#### Read Box Storage
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
// If contract uses boxes
|
|
127
|
+
const boxValue = await client.state.box.myBox()
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
#### Bulk Opt-In/Opt-Out
|
|
131
|
+
|
|
132
|
+
For batch operations across multiple assets:
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
// Bulk opt-in to multiple assets
|
|
136
|
+
const group = algorand.newGroup()
|
|
137
|
+
for (const assetId of assetIds) {
|
|
138
|
+
group.addAssetOptIn({ sender: account.addr, assetId })
|
|
139
|
+
}
|
|
140
|
+
await group.send()
|
|
141
|
+
|
|
142
|
+
// Bulk opt-out from multiple assets
|
|
143
|
+
const closeGroup = algorand.newGroup()
|
|
144
|
+
for (const assetId of assetIds) {
|
|
145
|
+
closeGroup.addAssetOptOut({ sender: account.addr, assetId, creator: creatorAddr })
|
|
146
|
+
}
|
|
147
|
+
await closeGroup.send()
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Important Rules / Guidelines
|
|
151
|
+
|
|
152
|
+
- **Always build before deploying**: Run `algokit project run build` to generate fresh artifacts
|
|
153
|
+
- **Use generated clients**: They provide type safety and handle ABI encoding
|
|
154
|
+
- **Check App ID**: Get it from deployment output, don't hardcode across environments
|
|
155
|
+
- **Use environment variables**: Store sensitive data like mnemonics in `.env`
|
|
156
|
+
- **Localnet accounts**: Use `algorand.account.fromEnvironment('DEPLOYER')` for localnet
|
|
157
|
+
|
|
158
|
+
## Common Variations / Edge Cases
|
|
159
|
+
|
|
160
|
+
| Scenario | Approach |
|
|
161
|
+
|----------|----------|
|
|
162
|
+
| Deploy to testnet | `algokit project deploy testnet` (requires funded account) |
|
|
163
|
+
| Custom sender | Create account with `algorand.account.fromMnemonic()` |
|
|
164
|
+
| Multiple contracts | Create separate client instances for each |
|
|
165
|
+
| State not found | Ensure app is deployed and App ID is correct |
|
|
166
|
+
| Method not found | Rebuild contract and regenerate client |
|
|
167
|
+
|
|
168
|
+
## Environment Setup
|
|
169
|
+
|
|
170
|
+
For non-localnet deployments, set environment variables:
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
# .env file
|
|
174
|
+
ALGORAND_NETWORK=testnet
|
|
175
|
+
DEPLOYER_MNEMONIC="your twenty four word mnemonic phrase here"
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## References / Further Reading
|
|
179
|
+
|
|
180
|
+
- [CLI Commands Reference](./call-smart-contracts-reference.md)
|
|
181
|
+
- [AlgoKit Utils Documentation](https://dev.algorand.co/algokit/utils/typescript/)
|
|
182
|
+
- [ARC-56 App Spec Standard](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0056.md)
|
|
183
|
+
- [Testing Contracts](./test-smart-contracts.md)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# AlgoKit Init CLI Reference (TypeScript)
|
|
2
|
+
|
|
3
|
+
## TypeScript Presets
|
|
4
|
+
|
|
5
|
+
| Preset | Description |
|
|
6
|
+
| ------------ | ---------------------------- |
|
|
7
|
+
| `Starter` | Simple starting point |
|
|
8
|
+
| `Production` | Tests, CI/CD, linting, audit |
|
|
9
|
+
|
|
10
|
+
## TypeScript Templates
|
|
11
|
+
|
|
12
|
+
| Template | Use Case |
|
|
13
|
+
| ------------ | --------------------------------------------- |
|
|
14
|
+
| `typescript` | Smart contracts (Algorand TypeScript/PuyaTs) |
|
|
15
|
+
| `react` | Frontend dApp with wallet integration |
|
|
16
|
+
| `fullstack` | Smart contracts + React frontend combined |
|
|
17
|
+
|
|
18
|
+
## Command Patterns
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# TypeScript (Production preset)
|
|
22
|
+
algokit init -n <name> -t typescript --answer preset_name production --answer author_name "<author>" --defaults
|
|
23
|
+
|
|
24
|
+
# TypeScript (Starter preset)
|
|
25
|
+
algokit init -n <name> -t typescript --answer author_name "<author>" --defaults
|
|
26
|
+
|
|
27
|
+
# React frontend
|
|
28
|
+
algokit init -n <name> -t react --defaults
|
|
29
|
+
|
|
30
|
+
# Fullstack (contracts + React frontend)
|
|
31
|
+
algokit init -n <name> -t fullstack --defaults
|
|
32
|
+
|
|
33
|
+
# Skip git and bootstrap
|
|
34
|
+
algokit init -n <name> -t typescript --no-git --no-bootstrap --defaults
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Options
|
|
38
|
+
|
|
39
|
+
| Flag | Description |
|
|
40
|
+
| ---------------------------- | ------------------------------------------------ |
|
|
41
|
+
| `-n, --name <name>` | Project directory name (required) |
|
|
42
|
+
| `-t, --template <name>` | Template name (`typescript`, `react`, `fullstack`)|
|
|
43
|
+
| `--answer "<key>" "<value>"` | Answer template prompts |
|
|
44
|
+
| `--defaults` | Accept all defaults |
|
|
45
|
+
| `--no-git` | Skip git initialization |
|
|
46
|
+
| `--no-bootstrap` | Skip dependency installation |
|
|
47
|
+
| `--workspace` | Create within workspace structure (default) |
|
|
48
|
+
| `--no-workspace` | Create standalone project |
|
|
49
|
+
|
|
50
|
+
## Full Reference
|
|
51
|
+
|
|
52
|
+
- [AlgoKit Init Command](https://dev.algorand.co/reference/algokit-cli/#init)
|
|
53
|
+
- [AlgoKit Templates](https://dev.algorand.co/algokit/official-algokit-templates/)
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# AlgoKit Project Initialization (TypeScript)
|
|
2
|
+
|
|
3
|
+
Create new Algorand TypeScript projects using AlgoKit's official templates.
|
|
4
|
+
|
|
5
|
+
## Overview / Core Workflow
|
|
6
|
+
|
|
7
|
+
1. Confirm project details with user (name, preset, customizations)
|
|
8
|
+
2. Run `algokit init` with the TypeScript template
|
|
9
|
+
3. Handle any initialization errors
|
|
10
|
+
4. Provide next steps for building/testing
|
|
11
|
+
|
|
12
|
+
## How to Proceed
|
|
13
|
+
|
|
14
|
+
1. **Confirm project details with user:**
|
|
15
|
+
- Project name (directory name)
|
|
16
|
+
- Preset choice (Production or Starter)
|
|
17
|
+
- Any customizations (`--no-git`, `--no-bootstrap`, author name)
|
|
18
|
+
|
|
19
|
+
2. **Run initialization command:**
|
|
20
|
+
|
|
21
|
+
**TypeScript (Production Preset):**
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
algokit init -n <project-name> -t typescript --answer preset_name production --answer author_name "<name>" --defaults
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
**TypeScript (Starter Preset):**
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
algokit init -n <project-name> -t typescript --answer author_name "<name>" --defaults
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
3. **Handle errors:**
|
|
34
|
+
- Check if project directory already exists
|
|
35
|
+
- Verify AlgoKit is installed: `algokit --version`
|
|
36
|
+
- Ensure target directory is writable
|
|
37
|
+
|
|
38
|
+
4. **Provide next steps:**
|
|
39
|
+
- `cd <project-name>`
|
|
40
|
+
- `algokit project run build` -- Compile contracts
|
|
41
|
+
- `algokit project run test` -- Run test suite
|
|
42
|
+
- `algokit localnet start` -- Start local network (if deploying)
|
|
43
|
+
- `algokit project run deploy` -- Deploy contracts to local network
|
|
44
|
+
|
|
45
|
+
## TypeScript Templates
|
|
46
|
+
|
|
47
|
+
| Template | Use Case |
|
|
48
|
+
| ------------ | --------------------------------------------- |
|
|
49
|
+
| `typescript` | Smart contracts (Algorand TypeScript/PuyaTs) |
|
|
50
|
+
| `react` | Frontend dApp with wallet integration |
|
|
51
|
+
| `fullstack` | Smart contracts + React frontend combined |
|
|
52
|
+
|
|
53
|
+
### React Frontend
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
algokit init -n <project-name> -t react --defaults
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Fullstack (Contracts + React Frontend)
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
algokit init -n <project-name> -t fullstack --defaults
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## TypeScript-Specific Customizations
|
|
66
|
+
|
|
67
|
+
| Customization | Command |
|
|
68
|
+
|---------------|---------|
|
|
69
|
+
| Set author name | `--answer author_name "Your Name"` |
|
|
70
|
+
| Production preset | `--answer preset_name production` |
|
|
71
|
+
| Starter preset | Omit `preset_name` (default) |
|
|
72
|
+
| Skip git init | `--no-git` |
|
|
73
|
+
| Skip dependency install | `--no-bootstrap` |
|
|
74
|
+
|
|
75
|
+
## Important Rules / Guidelines
|
|
76
|
+
|
|
77
|
+
- **Always confirm with user before executing** -- Never run `algokit init` without explicit confirmation
|
|
78
|
+
- **Use production preset** -- For any serious project because it includes testing framework and deployment scripts
|
|
79
|
+
- **Include author name** -- Pass `--answer author_name "<name>"` for attribution
|
|
80
|
+
- **Use `--defaults`** -- Accepts all other default values for non-interactive mode
|
|
81
|
+
|
|
82
|
+
## References / Further Reading
|
|
83
|
+
|
|
84
|
+
- [CLI Reference](./create-project-reference.md)
|
|
85
|
+
- [AlgoKit CLI Init Documentation](https://dev.algorand.co/algokit/cli/init/)
|
|
86
|
+
- [AlgoKit CLI Init Reference](https://dev.algorand.co/reference/algokit-cli#init)
|