.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));
然而,同样的错误仍然存在。如何解决这个问题?
发生错误不是因为未设置记录器对象,而是因为未设置客户端对象。请注意,事务请求与请求不同
getRecord
,因此客户端对象也需要传递到其中。以下代码执行
.getReceipt(client)
(而不是.getReceipt()
),并且这不应引发问题中描述的错误。