Description
Environment
starknet.js version: 6.24.1
Context: Next.js app using starknet.js to interact with contracts
Description
When calling a contract method using Contract.call in starknet.js, I intermittently get the following error:
TypeError: Cannot read properties of undefined (reading 'flat')
at _CallData.parse (index.mjs:3001:39)
at eval (index.mjs:9156:28)
at async getMinimumLoanAmount (Rewards.tsx:323:23)
at async Promise.allSettled (your-borrow/index 1)
'err in getMinimumLoanAmount'
Sometimes the call works, but other times it fails with this error. The error seems to originate from the _CallData.parse function inside starknet.js.
Example Code
typescript
export async function getMinimumLoanAmount(dToken: any) {
try {
const provider = getProvider();
const governorContract = new Contract(
governorAbi,
governorAddress,
provider
);
const result: any = await governorContract.call(
'get_minimum_loan_amount',
[tokenAddressMap[dToken]],
{ blockIdentifier: 'pending' }
);
console.log({ result1: result });
const res = parseAmount(
uint256.uint256ToBN(result?._get_minimum_loan_amount).toString(),
tokenDecimalsMap[dToken]
);
return res;
} catch (err) {
console.log(err, 'err in getMinimumLoanAmount');
}
}
Steps to Reproduce
Call the above function multiple times (sometimes in parallel).
Occasionally, the call fails with the error above.
Additional Info
The error is intermittent; sometimes the call works fine.
The issue appears to be related to how the call data is parsed internally in starknet.js.
Expected Behavior
The contract call should either succeed or return a well-formed error, but it should not throw a TypeError related to undefined .flat.
Actual Behavior
Intermittent TypeError is thrown from within starknet.js.
Request
Please investigate the cause of this intermittent TypeError in starknet.js and suggest a workaround or fix.