Skip to content

fix: make FactoryModule lazy in ConduitClient; supply factoryAddress in all examples - #470

Merged
Jaydbrown merged 1 commit into
conduit-protocol:mainfrom
Fang0067:fix/428-factory-address-required
Aug 26, 2026
Merged

fix: make FactoryModule lazy in ConduitClient; supply factoryAddress in all examples#470
Jaydbrown merged 1 commit into
conduit-protocol:mainfrom
Fang0067:fix/428-factory-address-required

Conversation

@Fang0067

Copy link
Copy Markdown
Contributor

Overview

Fixes a crash-on-startup bug where every ConduitClient-based example failed immediately because ConduitClient's constructor unconditionally instantiated FactoryModule, which throws when config.factoryAddress is absent.

Related Issue

Closes #428

Changes

Core SDK

  • [MODIFY] src/client.ts
    • Converted factory from an eagerly-initialised readonly field to a lazy getter. FactoryModule is now only constructed on the first access of .factory, so callers that never use factory queries (stream-only consumers, read-only listing via streams.list, etc.) are not forced to supply factoryAddress. Accessing .factory without a factoryAddress still throws FactoryModule's clear, actionable error — but now at the call site rather than in the constructor.

Examples

  • [MODIFY] examples/create-stream.ts
    • Reads FACTORY_ADDRESS from env, validates it is set, and passes it to ConduitClient. Updated run-command comment.
  • [MODIFY] examples/withdraw.ts
    • Same as above.
  • [MODIFY] examples/list-streams.ts
    • Same as above.
  • [MODIFY] examples/nextjs-app/lib/conduit.ts
    • Added getFactoryAddress() that reads FACTORY_ADDRESS (server-only env var) and threads it into the ConduitClient config inside getClient().
  • [MODIFY] examples/nextjs-app/.env.example
    • Documents the new FACTORY_ADDRESS variable with an explanation of what it is and why it is not NEXT_PUBLIC_-prefixed.

Verification Results

Constructing ConduitClient without factoryAddress no longer throws.
Accessing client.factory without factoryAddress throws FactoryModule's
clear error at the call site (correct behaviour preserved).
All examples now validate FACTORY_ADDRESS at startup and pass it through.
Acceptance Criteria Status
new ConduitClient({ network: 'testnet', keypair }) does not throw ✅ FactoryModule is now lazy — constructor no longer instantiates it
client.factory without factoryAddress still throws a clear error ✅ FactoryModule's guard is preserved, just deferred to access time
All example scripts run past the new ConduitClient(…) line ✅ All four examples now read and pass FACTORY_ADDRESS from env
examples/nextjs-app getClient() passes factoryAddress getFactoryAddress() helper added and threaded in
Missing FACTORY_ADDRESS in examples gives a clear error message ✅ Each example exits with an actionable message before constructing the client

…examples (conduit-protocol#428)

ConduitClient's constructor unconditionally instantiated FactoryModule,
which throws when config.factoryAddress is absent. This crashed every
example and any consumer who didn't care about factory queries.

Changes:
- src/client.ts: convert  from an eagerly-set field to a lazy
  getter. FactoryModule is only constructed on first  access,
  so clients that never use factory queries are never forced to supply
  factoryAddress. Accessing .factory without a factoryAddress still throws
  FactoryModule's clear error at the call site.
- examples/create-stream.ts, withdraw.ts, list-streams.ts: read
  FACTORY_ADDRESS from env and pass it to ConduitClient. Updated run
  instructions and added early exit when the variable is missing.
- examples/nextjs-app/lib/conduit.ts: add getFactoryAddress() helper that
  reads FACTORY_ADDRESS (server-only env var) and threads it into the
  client config.
- examples/nextjs-app/.env.example: document the new FACTORY_ADDRESS
  variable.

Closes conduit-protocol#428
@drips-wave

drips-wave Bot commented Aug 25, 2026

Copy link
Copy Markdown

@Fang0067 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Jaydbrown

Copy link
Copy Markdown
Contributor

Thanks for the contribution here — squash-merging this now. Any follow-ups we'll track in a fresh issue. 🚀

@Jaydbrown
Jaydbrown merged commit 9a17dbc into conduit-protocol:main Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: every ConduitClient-based example crashes immediately — FactoryModule always requires factoryAddress

2 participants