This repository was archived by the owner on Mar 5, 2025. It is now read-only.
Understanding Contract Method Call Return Types in web3.js 4 #7415
Unanswered
BigBadAlien
asked this question in
Q&A
Replies: 1 comment
-
Yes, the return type from Web3.js v4 contract method calls is not strictly enforced due to the generic typing system. const balance: bigint = await contract.methods.balanceOf(holder).call(); This ensures type safety and prevents unintended errors. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
According to the documentation at https://docs.web3js.org/guides/smart_contracts/infer_contract_types/:
The
balanceOf
method is typed, but the variablebalance
has the typeMatchPrimitiveType<"uint8", unknown>
. It doesn't throw an error in the case:This suggests that the return type isn’t strictly enforced. I suppose this might be due to formatters flexibility. Is the intended approach to always set the return type explicitly, like
const balance: bigint
?Beta Was this translation helpful? Give feedback.
All reactions