hedera-sdk-js
hedera-sdk-js copied to clipboard
SDK fails to reconnect to working node
Description
SDK Client is droping connection to a working node randomly. This is seen to happen only on setup with 1 node after modularization.
Error: max attempts of 10 was reached for request with last error being: GrpcServiceError: Connection dropped
at TransferTransaction.execute (file:///Users/georgi-lazarov/Documents/GitHub/hedera-sdk-js/src/Executable.js:738:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async main (file:///Users/georgi-lazarov/Documents/GitHub/hedera-sdk-js/examples/timeout-issue.js:65:30)
Steps to reproduce
- Lower docker resources to 3 CPU and 5GB RAM
- Start local-node
- Run this snippet
import {
Wallet,
LocalProvider,
PrivateKey,
PublicKey,
Hbar,
AccountId,
AccountBalanceQuery,
AccountInfoQuery,
TransferTransaction,
} from "@hashgraph/sdk";
import dotenv from "dotenv";
dotenv.config();
async function main() {
if (
process.env.OPERATOR_ID == null ||
process.env.OPERATOR_KEY == null ||
process.env.HEDERA_NETWORK == null
) {
throw new Error(
"Environment variables OPERATOR_ID, HEDERA_NETWORK, and OPERATOR_KEY are required.",
);
}
const provider = new LocalProvider();
const wallet = new Wallet(
process.env.OPERATOR_ID,
process.env.OPERATOR_KEY,
provider,
);
console.log('"Creating" a new account');
const privateKey = PrivateKey.generateED25519();
const publicKey = privateKey.publicKey;
const aliasAccountId = publicKey.toAccountId(0, 0);
console.log(`New account ID: ${aliasAccountId.toString()}`);
console.log(`Just the aliasKey: ${aliasAccountId.aliasKey.toString()}`);
AccountId.fromString(
"0.0.302a300506032b6570032100114e6abc371b82dab5c15ea149f02d34a012087b163516dd70f44acafabf7777",
);
PublicKey.fromString(
"302a300506032b6570032100114e6abc371b82dab5c15ea149f02d34a012087b163516dd70f44acafabf7777",
).toAccountId(0, 0);
console.log("Transferring some Hbar to the new account");
let count = 1;
while (true) {
try {
console.log(`Attempt number: ${count}`);
let transaction = await new TransferTransaction()
.addHbarTransfer(wallet.getAccountId(), new Hbar(1).negated())
.addHbarTransfer(aliasAccountId, new Hbar(1))
.freezeWithSigner(wallet);
transaction = await transaction.signWithSigner(wallet);
const response = await transaction.executeWithSigner(wallet);
await response.getReceiptWithSigner(wallet);
const balance = await new AccountBalanceQuery()
.setNodeAccountIds([response.nodeId])
.setAccountId(aliasAccountId)
.executeWithSigner(wallet);
console.log(`Balances of the new account: ${balance.toString()}`);
console.log("\x1b[32mExample complete!\x1b[0m");
} catch (error) {
console.error(error);
console.log("\x1b[31mExample failed!\x1b[0m");
}
count++;
}
}
void main();
- Observer after couple hundred of transactions the error.
Additional context
No response
Hedera network
other
Version
main
Operating system
None