use-algokit-utils

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

AlgoKit Utils

AlgoKit Utils

Use AlgoKit Utils to interact with the Algorand blockchain from TypeScript or Python applications.
使用 AlgoKit Utils 在 TypeScript 或 Python 应用中与 Algorand 区块链进行交互。

Overview / Core Workflow

概述 / 核心工作流

  1. Create an
    AlgorandClient
    instance
  2. Get or create accounts for signing
  3. Send transactions using
    algorand.send.*
    methods
  4. Or compose groups using
    algorand.newGroup()
  1. 创建
    AlgorandClient
    实例
  2. 获取或创建用于签名的账户
  3. 使用
    algorand.send.*
    方法发送交易
  4. 或使用
    algorand.newGroup()
    组合交易组

How to proceed

操作步骤

  1. Initialize AlgorandClient:
    TypeScript:
    typescript
    import { AlgorandClient } from '@algorandfoundation/algokit-utils'
    
    const algorand = AlgorandClient.fromEnvironment()
    // Or: AlgorandClient.defaultLocalNet()
    // Or: AlgorandClient.testNet()
    // Or: AlgorandClient.mainNet()
    Python:
    python
    from algokit_utils import AlgorandClient
    
    algorand = AlgorandClient.from_environment()
    # Or: AlgorandClient.default_localnet()
    # Or: AlgorandClient.testnet()
    # Or: AlgorandClient.mainnet()
  2. Get accounts:
    TypeScript:
    typescript
    const account = await algorand.account.fromEnvironment('DEPLOYER')
    Python:
    python
    account = algorand.account.from_environment("DEPLOYER")
  3. Send transactions:
    TypeScript:
    typescript
    await algorand.send.payment({
      sender: account.addr,
      receiver: 'RECEIVERADDRESS',
      amount: algo(1),
    })
    Python:
    python
    algorand.send.payment(PaymentParams(
      sender=account.address,
      receiver="RECEIVERADDRESS",
      amount=AlgoAmount(algo=1),
    ))
  1. 初始化 AlgorandClient:
    TypeScript:
    typescript
    import { AlgorandClient } from '@algorandfoundation/algokit-utils'
    
    const algorand = AlgorandClient.fromEnvironment()
    // Or: AlgorandClient.defaultLocalNet()
    // Or: AlgorandClient.testNet()
    // Or: AlgorandClient.mainNet()
    Python:
    python
    from algokit_utils import AlgorandClient
    
    algorand = AlgorandClient.from_environment()
    # Or: AlgorandClient.default_localnet()
    # Or: AlgorandClient.testnet()
    # Or: AlgorandClient.mainnet()
  2. 获取账户:
    TypeScript:
    typescript
    const account = await algorand.account.fromEnvironment('DEPLOYER')
    Python:
    python
    account = algorand.account.from_environment("DEPLOYER")
  3. 发送交易:
    TypeScript:
    typescript
    await algorand.send.payment({
      sender: account.addr,
      receiver: 'RECEIVERADDRESS',
      amount: algo(1),
    })
    Python:
    python
    algorand.send.payment(PaymentParams(
      sender=account.address,
      receiver="RECEIVERADDRESS",
      amount=AlgoAmount(algo=1),
    ))

Important Rules / Guidelines

重要规则 / 指南

  • Use AlgorandClient — It's the main entry point; avoid deprecated function-based APIs
  • Default to fromEnvironment() — Works locally and in production via env vars
  • Register signers — Use
    algorand.account
    to get accounts; signers are auto-registered
  • Use algo() helper — For TypeScript, use
    algo(1)
    instead of raw microAlgos
  • 使用 AlgorandClient — 这是主要入口点;避免使用已弃用的基于函数的 API
  • 优先使用 fromEnvironment() — 通过环境变量可在本地和生产环境中使用
  • 注册签名者 — 使用
    algorand.account
    获取账户;签名者会自动注册
  • 使用 algo() 辅助函数 — 在 TypeScript 中,使用
    algo(1)
    替代原生 microAlgos 数值

Common Variations / Edge Cases

常见变体 / 边缘场景

ScenarioApproach
LocalNet development
AlgorandClient.defaultLocalNet()
TestNet/MainNet
AlgorandClient.testNet()
or
.mainNet()
Custom node
AlgorandClient.fromConfig({ algodConfig: {...} })
Deploy contractUse typed app client factory (see app-client docs)
Transaction groups
algorand.newGroup().addPayment(...).addAssetOptIn(...).send()
场景处理方式
LocalNet 开发
AlgorandClient.defaultLocalNet()
TestNet/MainNet 开发
AlgorandClient.testNet()
.mainNet()
自定义节点
AlgorandClient.fromConfig({ algodConfig: {...} })
部署合约使用类型化应用客户端工厂(查看 app-client 文档)
交易组
algorand.newGroup().addPayment(...).addAssetOptIn(...).send()

References / Further Reading

参考资料 / 扩展阅读

Language-specific references are organized in subfolders:
  • TypeScript (
    references/typescript/
    ): AlgorandClient
  • Python (
    references/python/
    ): AlgorandClient
External documentation:
特定语言的参考资料按子文件夹分类:
  • TypeScript
    references/typescript/
    ):AlgorandClient
  • Python
    references/python/
    ):AlgorandClient
外部文档: