AlgoKitUtils区块链交互库 use-algokit-utils

AlgoKit Utils 是一个用于与 Algorand 区块链交互的开发库,支持 TypeScript 和 Python。它提供了连接 Algorand 网络、发送支付交易、管理账户、部署智能合约以及组合交易组等核心功能。关键词:Algorand 区块链,智能合约开发,DApp 开发,Web3,Python SDK,TypeScript SDK,AlgoKit,区块链交互,交易发送,账户管理。

DApp开发 0 次安装 0 次浏览 更新于 3/4/2026

名称: 使用-algokit-utils 描述: AlgoKit Utils库,用于从TypeScript或Python应用程序与Algorand区块链交互。适用于连接Algorand网络(LocalNet、TestNet、MainNet)、发送支付或转移资产、创建和管理账户、从客户端代码部署或交互智能合约,或组合交易组。不适用于编写智能合约代码(请使用构建智能合约技能)。强触发词包括“如何连接到Algorand?”、“发送支付交易”、“创建账户”、“部署我的合约”、“获取AlgorandClient”、“AlgorandClient.fromEnvironment”。

AlgoKit Utils

使用AlgoKit Utils从TypeScript或Python应用程序与Algorand区块链交互。

概述 / 核心工作流

  1. 创建一个 AlgorandClient 实例
  2. 获取或创建用于签名的账户
  3. 使用 algorand.send.* 方法发送交易
  4. 或使用 algorand.newGroup() 组合交易组

如何操作

  1. 初始化 AlgorandClient:

    TypeScript:

    import { AlgorandClient } from '@algorandfoundation/algokit-utils'
    
    const algorand = AlgorandClient.fromEnvironment()
    // 或者: AlgorandClient.defaultLocalNet()
    // 或者: AlgorandClient.testNet()
    // 或者: AlgorandClient.mainNet()
    

    Python:

    from algokit_utils import AlgorandClient
    
    algorand = AlgorandClient.from_environment()
    # 或者: AlgorandClient.default_localnet()
    # 或者: AlgorandClient.testnet()
    # 或者: AlgorandClient.mainnet()
    
  2. 获取账户:

    TypeScript:

    const account = await algorand.account.fromEnvironment('DEPLOYER')
    

    Python:

    account = algorand.account.from_environment("DEPLOYER")
    
  3. 发送交易:

    TypeScript:

    await algorand.send.payment({
      sender: account.addr,
      receiver: 'RECEIVERADDRESS',
      amount: algo(1),
    })
    

    Python:

    algorand.send.payment(PaymentParams(
      sender=account.address,
      receiver="RECEIVERADDRESS",
      amount=AlgoAmount(algo=1),
    ))
    

重要规则 / 指南

  • 使用 AlgorandClient — 这是主要入口点;避免使用已弃用的基于函数的API
  • 默认使用 fromEnvironment() — 通过环境变量在本地和生产环境中均可工作
  • 注册签名者 — 使用 algorand.account 获取账户;签名者会自动注册
  • 使用 algo() 辅助函数 — 对于TypeScript,使用 algo(1) 而不是原始的微Algo

常见变体 / 边缘情况

场景 方法
LocalNet 开发 AlgorandClient.defaultLocalNet()
TestNet/MainNet AlgorandClient.testNet().mainNet()
自定义节点 AlgorandClient.fromConfig({ algodConfig: {...} })
部署合约 使用类型化的应用客户端工厂(参见应用客户端文档)
交易组 algorand.newGroup().addPayment(...).addAssetOptIn(...).send()

参考 / 延伸阅读

语言特定的参考文档组织在子文件夹中:

外部文档: