The following code throws an error when .getReceipt()
is invoked.
Note that the transaction itself is successful.
const hcsTopicCreateTx = await new TopicCreateTransaction()
.freezeWith(client)
.sign(operatorKey);
const hcsTopicCreateTxResponse = await hcsTopicCreateTx.execute(client);
const hcsTopicCreateReceipt = await hcsTopicCreateTxResponse.getReceipt();
This is the error:
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)
Why is _logger
missing?
Here is how the client
object was initialised:
const client = Client.forTestnet().setOperator(operatorId, operatorKey);
Also tried manually initialising the logger on client
like so:
const client = Client.forTestnet().setOperator(operatorId, operatorKey);
client.setLogger(new Logger(LogLevel.Warn));
However, the same error persisted. How can this be resolved?
The error occurs not because the logger object isn't set,
but because the client object is not set.
Note that the transaction request is different from the getRecord
request,
and therefore the client object needs to be passed into that as well.
The following code does .getReceipt(client)
(instead of .getReceipt()
),
and this should not throw the error described in your question.
const hcsTopicCreateTx = await new TopicCreateTransaction()
.freezeWith(client)
.sign(operatorKey);
const hcsTopicCreateTxResponse = await hcsTopicCreateTx.execute(client);
const hcsTopicCreateReceipt = await hcsTopicCreateTxResponse.getReceipt(client);