【问题标题】:How do we pass the string as an application argument? (Algorand, JS SDK)我们如何将字符串作为应用程序参数传递? (Algorand, JS SDK)
【发布时间】:2022-10-19 02:23:50
【问题描述】:

我正在使用 Algorand JS SDK,但不知道如何将字符串作为应用程序参数传递。我尝试了多种方法,但没有得到任何积极的结果。

【问题讨论】:

    标签: javascript algorand


    【解决方案1】:

    您可以在此处查看示例: https://developer.algorand.org/docs/get-started/dapps/pyteal/#deploy-and-communicate-with-the-smart-contract

    请特别参阅此代码,它将字符串 "setup" 作为应用程序参数传递。

        setupTxn = transaction.ApplicationCallTxn(
            sender=funder.getAddress(),
            index=appID,
            on_complete=transaction.OnComplete.NoOpOC,
            app_args=[b"setup"],
            foreign_assets=[nftID],
            sp=suggestedParams,
        )
    

    重要的一点是字符串必须编码为字节,因此b 位于b"setup" 的开头。 如果字符串是 Python string 对象,则需要使用 .encode() 方法。 有关详细信息,请参阅https://docs.python.org/3/howto/unicode.html#converting-to-bytes

    另请注意,如今,强烈建议创建与 ABI 兼容的智能合约。 在这种情况下,调用智能合约的最佳方式是使用原子事务编写器:https://developer.algorand.org/docs/get-details/atc/,而不是直接创建ApplicationCallTxn 对象。

    然而,关于将字符串转换为字节的相同评论仍然适用。

    【讨论】:

      猜你喜欢
      • 2022-08-11
      • 1970-01-01
      • 1970-01-01
      • 2013-09-20
      • 1970-01-01
      • 1970-01-01
      • 2020-01-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多