为什么 `getRecord()` 由于 `_logger` 相关错误而失败? (使用Hedera SDK)

问题描述 投票:0回答:1

调用

.getReceipt()
时,以下代码会引发错误。 请注意,交易本身已成功。

    const hcsTopicCreateTx = await new TopicCreateTransaction()
        .freezeWith(client)
        .sign(operatorKey);
    const hcsTopicCreateTxResponse = await hcsTopicCreateTx.execute(client);
    const hcsTopicCreateReceipt = await hcsTopicCreateTxResponse.getReceipt();

这是错误:

file:///Users/user/code/hedera/hedera-code-snippets/hcs-topic-permissioned-write/node_modules/@hashgraph/sdk/src/Executable.js:518
                ? client._logger != null
                         ^
TypeError: Cannot read properties of undefined (reading '_logger')
    at TransactionReceiptQuery.execute (file:///Users/user/code/hedera/hedera-code-snippets/hcs-topic-permissioned-write/node_modules/@hashgraph/sdk/src/Executable.js:518:26)
    at TransactionResponse.getReceipt (file:///Users/user/code/hedera/hedera-code-snippets/hcs-topic-permissioned-write/node_modules/@hashgraph/sdk/src/transaction/TransactionResponse.js:81:54)
    at main (file:///Users/user/code/hedera/hedera-code-snippets/hcs-topic-permissioned-write/hcs-write.js:60:66)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

为什么缺少

_logger

以下是

client
对象的初始化方式:

const client = Client.forTestnet().setOperator(operatorId, operatorKey);

还尝试在

client
上手动初始化记录器,如下所示:

const client = Client.forTestnet().setOperator(operatorId, operatorKey);
client.setLogger(new Logger(LogLevel.Warn));

但是,同样的错误仍然存在。怎么解决这个问题?

hedera-hashgraph
1个回答
0
投票

发生错误不是,因为没有设置记录器对象, 但因为客户端对象没有设置。 请注意,交易请求与 getRecord 请求

不同
, 因此客户端对象也需要传递给它。 以下代码执行
.getReceipt(client)
(而不是
.getReceipt()
, 这不应该引发您问题中描述的错误。

    const hcsTopicCreateTx = await new TopicCreateTransaction()
        .freezeWith(client)
        .sign(operatorKey);
    const hcsTopicCreateTxResponse = await hcsTopicCreateTx.execute(client);
    const hcsTopicCreateReceipt = await hcsTopicCreateTxResponse.getReceipt(client);
© www.soinside.com 2019 - 2024. All rights reserved.