name: search-algorand-examples description: 在GitHub上搜索Algorand智能合约示例和模式。适用于查找特定模式(BoxMap、内部交易)的示例实现、查询合约功能用法、发现Algorand代码库或从algorandfoundation代码库检索文件。强触发词包括“查找…的示例”、“展示如何使用BoxMap”、“搜索投票合约示例”、“从puya-ts示例获取代码”、“查找Algorand NFT代码库”。
搜索Algorand示例
使用GitHub工具从Algorand Foundation代码库中查找可运行的合约示例和代码模式。
概述 / 核心工作流程
- 确定用户需要的模式或示例
- 选择合适的工具(
github_search_code、github_get_file_contents或github_search_repositories) - 优先搜索官方代码库(devportal-code-examples、puya-ts)
- 检索相关文件
- 同时获取对应的测试文件(如果适用)
操作步骤
-
确定搜索类型:
- 查找特定模式 → 使用
github_search_code - 需要特定文件 → 使用
github_get_file_contents - 发现代码库 → 使用
github_search_repositories
- 查找特定模式 → 使用
-
优先搜索官方代码库:
优先级 代码库 最适合 1 algorandfoundation/devportal-code-examples初学者友好模式 2 algorandfoundation/puya-ts高级TypeScript示例 3 algorandfoundation/puyaPython示例 4 algorandfoundation/algokit-*模板和工具 -
执行搜索:
# 搜索代码模式 github_search_code query:"BoxMap org:algorandfoundation language:typescript" # 获取特定文件 github_get_file_contents owner:algorandfoundation repo:puya-ts path:examples/voting/contract.algo.ts # 列出目录内容 github_get_file_contents owner:algorandfoundation repo:puya-ts path:examples # 查找代码库 github_search_repositories query:"topic:algorand smart-contract" -
始终获取测试文件:
- 对于任何合约文件,检查对应的
*.spec.ts或*_test.py - 测试文件展示如何调用方法和验证行为
- 对于任何合约文件,检查对应的
重要规则 / 指南
- 优先搜索algorandfoundation — 官方代码库包含经过验证且最新的示例
- 始终包含测试文件 — 它们展示正确的使用模式
- 使用具体查询 — 包含
org:algorandfoundation和language:typescript以获得更好结果 - 检查devportal-code-examples中的文件路径:
- TypeScript:
projects/typescript-examples/contracts/ - Python:
projects/python-examples/contracts/
- TypeScript:
- 复杂模式优先选择puya-ts/examples — 投票、AMM、拍卖示例非常全面
如果GitHub MCP工具不可用
使用网页搜索作为备选方案:
- 代码搜索:
site:github.com algorandfoundation {模式} language:typescript - 特定文件:直接浏览
https://github.com/algorandfoundation/puya-ts/tree/main/examples - 代码库搜索:搜索
site:github.com algorand {主题}
可直接浏览的关键URL:
- https://github.com/algorandfoundation/devportal-code-examples
- https://github.com/algorandfoundation/puya-ts/tree/main/examples
- https://github.com/algorandfoundation/puya/tree/main/examples
常见变体 / 边缘情况
| 场景 | 方法 |
|---|---|
| 在algorandfoundation中未找到模式 | 扩展到整个GitHub搜索 |
| 需要Python而非TypeScript | 搜索algorandfoundation/puya |
| 查找部署模式 | 检查algokit-*-template代码库 |
| 需要ARC标准实现 | 在代码中搜索“ARC-{编号}” |