Hedera本地节点AccountCreateTransaction超时问题及解决
问题:Hedera本地网络执行AccountCreateTransaction时触发gRPC TIMEOUT错误
环境与代码
按照Hedera官方文档搭建本地网络,使用的Node.js代码如下:
const { Client, PrivateKey, Hbar, AccountId, AccountCreateTransaction, } = require("@hashgraph/sdk"); require('dotenv').config(); const myAccountId = process.env.MY_ACCOUNT_ID; const myPrivateKey = process.env.MY_PRIVATE_KEY; const myPublicKey = process.env.MY_PUBLIC_KEY; async function main() { console.log("account id is: " + process.env.MY_ACCOUNT_ID); const node = {"127.0.0.1:50211": new AccountId(3)}; const client = Client.forNetwork(node).setMirrorNetwork("127.0.0.1:5600"); //set the transaction fee paying account client.setOperator(myAccountId, myPrivateKey); console.log('success'); console.log(PrivateKey.fromString(myPublicKey)); const newAccount = await new AccountCreateTransaction() .setKey(PrivateKey.fromString(myPublicKey)) .setInitialBalance(new Hbar(1)) .execute(client); //Get receipt const receipt = await newAccount.getReceipt(client); //Get the account ID const newAccountId = receipt.accountId; console.log(newAccountId); } void main();
报错信息
执行代码时,在AccountCreateTransaction.execute()步骤持续报错:
/Users/{name}/Desktop/{org_name}/hello-hedera-js-sdk/node_modules/@hashgraph/sdk/lib/Executable.cjs:679 throw new Error(`max attempts of ${maxAttempts.toString()} was reached for request with last error being: ${persistentError != null ? persistentError.toString() : ""}`); ^ Error: max attempts of 10 was reached for request with last error being: GrpcServiceError: gRPC service failed with status: TIMEOUT at AccountCreateTransaction.execute (/Users/{name}/Desktop/{org_name}/hello-hedera-js-sdk/node_modules/@hashgraph/sdk/lib/Executable.cjs:679:11) at async main (/Users/drew/Desktop/Greensmith/hello-hedera-js-sdk/localtx.js:31:24)
排查过程
- 已确认Docker上的hedera-local-node集群启动状态正常
client.setOperator执行成功,控制台输出success- 尝试直接复用官方示例代码、删除并重装
node_modules,均无法解决问题
解决方案
最终定位问题根源为Docker内存不足,扩容Docker的可用内存后,问题得到解决。
内容的提问来源于stack exchange,提问作者Drew
相关产品推荐
相关产品推荐

