gpt4 book ai didi

move-lang - 如何在 Aptos Blockchain 上的 Move 模块中定义和查询读取功能?

转载 作者:行者123 更新时间:2023-12-05 02:25:58 25 4
gpt4 key购买 nike

在 Aptos Move 文档中,它解释了如何与公开“入口函数”的智能合约进行交互。在 hello_blockchain 示例中,使用了 set_message。

Move modules expose access points, also referred as entry functions. These access points can be called via transactions. The CLI allows for seamless access to these access points. The example Move module hello_blockchain exposes a set_message entry function that takes in a string. This can be called via the CLI:

但是,没有关于如何查询 get_message 函数的解释,在我看来,该函数类似于读取函数。

此外,也没有说明如何使用Python SDK查询读写函数。

两个问题:

  1. 是否可以使用 Python SDK 查询 Move 模块中的读/写函数?
  2. 如何在 Move 模块中定义读取函数?

最佳答案

如果您想读取帐户上的资源,您可以向 API 提交读取请求。例如,使用 curl:

curl https://fullnode.mainnet.aptoslabs.com/v1/accounts/<addr>/resource/<resource>

一个具体的例子:

curl https://fullnode.mainnet.aptoslabs.com/v1/accounts/0x00ffe770ccae2e373bc1f217585a1f97b5fa003cc169a27e1b4d6bfc8d3b243b/resource/0x3::token::TokenStore

这相当于:

Read the resource 0x3::token::TokenStore at account 0x00ffe770ccae2e373bc1f217585a1f97b5fa003cc169a27e1b4d6bfc8d3b243b.

在 Python SDK 中,您将执行如下操作:

client.account_resource(
"0x00ffe770ccae2e373bc1f217585a1f97b5fa003cc169a27e1b4d6bfc8d3b243b",
"0x3::token::TokenStore",
)

这使用此客户端方法:https://github.com/aptos-labs/aptos-core/blob/05d04ecc511f572380e1e8fe0bbc234f30645f0d/ecosystem/python/sdk/aptos_sdk/client.py#L63

hello_blockchain 示例中的 get_message 函数有些误导(我们可以对此进行改进)。不过有一个提示,请注意只有 entry 函数可以从外部调用运行(例如使用 CLI 命令 aptos move run)。所有其他函数只能从 Move 模块中调用。

更清楚的是:为了从 Aptos 区 block 链读取,您必须向读取 API 端点发出请求,而不是在 Move 模块中“读取函数”。

有关更多信息,请查看这些文档:https://aptos.dev/tutorials/your-first-transaction .

关于move-lang - 如何在 Aptos Blockchain 上的 Move 模块中定义和查询读取功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74133381/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com