# Several issues with Harmony SDK, making it difficult to use in production reliably

**URL:** <https://talk.harmony.one/t/several-issues-with-harmony-sdk-making-it-difficult-to-use-in-production-reliably/6580>\
**Category:** Web3\
**Created:** [November 30, 2021, 10:37pm UTC](https://talk.harmony.one/t/several-issues-with-harmony-sdk-making-it-difficult-to-use-in-production-reliably/6580 "2021-11-30T22:37:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ROYalty](https://yyz1.discourse-cdn.com/flex035/user_avatar/talk.harmony.one/royalty/32/1276_2.png) [@ROYalty](https://talk.harmony.one/u/ROYalty)\
**Post date:** [November 30, 2021, 10:37pm UTC](https://talk.harmony.one/t/several-issues-with-harmony-sdk-making-it-difficult-to-use-in-production-reliably/6580/1 "2021-11-30T22:37:47Z")

</div>

> <https://github.com/harmony-one/sdk/issues/106>
>
> Hi there.
> 
> Is it fair to say that the Harmony SDK should handle re-connects by… itself when using the websocket API? See code below on how we listen for events on a smart contract. We've noticed at some point events stop coming through. We only deployed this yesterday, and it stopped overnight, so it may possibly be some kind of inactivity timeout?
> 
> Any guidance on options we should use to prevent timeouts, if needed, would be appreciated.
> 
> Thank you!
> 
> \`\`\`javascript
> const HARMONY\_WS = new WSProvider('wss://ws.s0.t.hmny.io');
> 
> const {
> ChainID,
> ChainType,
> hexToNumber,
> numberToHex,
> fromWei,
> Units,
> Unit,
> } = require('@harmony-js/utils');
> 
> const wallet = new Wallet(
> new Messenger(
> HARMONY\_WS,
> ChainType.Harmony,
> ChainID.HmyMainnet,
> ),
> );
> const factory = new ContractFactory(wallet);
> const contractAddr = "0xfe1b516A7297eb03229A8B5AfAD80703911E81cB";
> const contract = factory.createContract(contractJson, contractAddr);
> 
> contract.events
> .Transfer()
> .on('data', async (event) =\> {
>     
> \[... rest of code omitted ...\]
> \`\`\`

> <https://github.com/harmony-one/sdk/issues/104>
>
> Hi
> 
> We're encountering another uncaught exception coming from the SDK. This ti…me when we use the \`blochamin.getTransactionCount()\` API
> 
> \`\`\`
> Error: RangeError: Maximum call stack size exceeded
> at Messenger.\<anonymous\>
> (/path/crypto\_royale/node\_modules/@harmony-js/network/dist/messenger/messenger.js:82:35)
> at step (/path/crypto\_royale/node\_modules/tslib/tslib.js:143:27)
> at Object.throw (/path/crypto\_royale/node\_modules/tslib/tslib.js:124:57)
> at rejected (/path/crypto\_royale/node\_modules/tslib/tslib.js:115:69)
> at runMicrotasks (\<anonymous\>)
> at processTicksAndRejections (node:internal/process/task\_queues:96:5)
> \`\`\`
> 
> Here is try-catch block in which the exception occurs:
> 
> \`\`\`javascript
> try {
> let count = await hmy.blockchain.getTransactionCount({ address: MAIN\_ACCOUNT })
> nonce = parseInt(count.result);
> while (nonce in transactionsInProgress) {
> nonce += 1;
> }
> transactionsInProgress\[nonce\] = true;
> } catch (err) {
> resolve({ success: false, error: \`Nonce creation error\` });
> return;
> }
> \`\`\`
> 
> Once this happens once, it keeps occuring until we restart the process.
> 
> Any thoughts/fixes/workarounds appreciated.

> <https://github.com/harmony-one/sdk/issues/98>
>
> For some reason I can't seem to gracefully recover from errors thrown in the SDK…, despite using the \`.on("error"\` handler AND wrapping the send function a try catch block. Any ideas why that's the case? Sample code below:
> \`\`\`javascript
> try {
> let sendoptions = {
> from: from,
> gasLimit: '250000',
> gasPrice: new hmy.utils.Unit(GAS\_PRICE\_GWEI).asGwei().toWei(),
> };
> await contract.methods
> .transfer(to, new Unit(amount).asOne().toWei())
> .send(sendoptions)
> .on("transactionHash", (\_hash) =\> {
> })
> .on("receipt", (\_receipt) =\> {
> })
> .on("confirmation", (confirmation) =\> {
> 
> })
> .on("error", (error) =\> {
> 
> });
> } catch (err) {
> 
> }
> \`\`\`
> 
> And the error that's taking down the process below:
> 
> \`\`\`
> 17:33:59: Withdraw: send failure within Harmony, reverting balance for wallet 8271
> 17:33:59: REJECTED
> /path/hidden/node\_modules/@harmony-js/transaction/dist/transactionBase.js:202
> throw new Error("The transaction is still not confirmed after " + maxAttempts + " attempts.");
> ^
> 
> Error: The transaction is still not confirmed after 20 attempts.
> at Transaction.\<anonymous\> (/path/hidden/node\_modules/@harmony-js/transaction/dist/transactionBase.js:202:31)
> at step (/path/hidden/node\_modules/tslib/tslib.js:143:27)
> at Object.next (/path/hidden/node\_modules/tslib/tslib.js:124:57)
> at fulfilled (/path/hidden/node\_modules/tslib/tslib.js:114:62)
> at runMicrotasks (\<anonymous\>)
> at processTicksAndRejections (node:internal/process/task\_queues:96:5)
> \`\`\`

Hi there.

I’m the dev of Crypto Royale ([https://cryptoroyale.one](https://cryptoroyale.one)).

I’ve filed the above 3 issues on github, that we’re experiencing with the Harmony SDK. We’re not getting much love/support with them. Is the Harmony SDK not recommended for use in production environments? Has anyone else come across these issues and solved them?

It’s really taking a toll on our ability to provide a smooth user experience.

Any help appreciated in advance.

ROYalty

---

<div class="post-metadata">

**Author:** ![tabasco\_ow](https://yyz1.discourse-cdn.com/flex035/user_avatar/talk.harmony.one/tabasco_ow/32/12757_2.png) [@tabasco\_ow](https://talk.harmony.one/u/tabasco_ow)\
**Post date:** [January 6, 2022, 8:34pm UTC](https://talk.harmony.one/t/several-issues-with-harmony-sdk-making-it-difficult-to-use-in-production-reliably/6580/2 "2022-01-06T20:34:08Z")

</div>

Seems to have been solved via Discord DMS;

Solution was to switch to web3.js instead of the Harmony SDK to avoid issues like this
