Skip to content

Check for smart contract initiation during runtime or compile time #5

@NikolasHaimerl

Description

@NikolasHaimerl

Missing Type Verification for smartContract Client

Description

Currently, there are no compile-time or run-time checks to verify that smartContract is a client for the MINER_TO_PEERID contract. The method smartContract.getPeerData may not exist.

With the current implementation, when the caller supplies a wrong smart contract client, the code fails with the following error:

❯ node
Welcome to Node.js v22.13.0.
Type ".help" for more information.
> {}.getPeerData(123)
Uncaught TypeError: {}.getPeerData is not a function

Impact

This is primarily a developer-experience issue. While the error message is somewhat descriptive, adding proper type checking could improve the developer experience by catching this issue earlier (at compile time) or providing more specific error messages (at runtime).

Suggested Solution

Consider implementing one or both of the following:

  1. Type checking: Add TypeScript interfaces or type definitions for the expected contract client, ensuring compile-time validation.

  2. Runtime validation: Add runtime validation to check if the provided smartContract has the required methods before attempting to use them, with a more descriptive error message.

Original Discussion

This issue was originally flagged by @bajtos in a PR review comment:
#2 (comment)

Metadata

Metadata

Labels

No labels
No labels

Projects

Status

📥 next

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions