ROYalty
November 30, 2021, 10:37pm
1
opened 09:15AM - 23 Nov 21 UTC
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 ...]
```
opened 02:53PM - 23 Oct 21 UTC
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.
opened 09:11PM - 02 Jul 21 UTC
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 ).
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
1 Like
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