fix: make FactoryModule lazy in ConduitClient; supply factoryAddress in all examples - #470
Merged
Jaydbrown merged 1 commit intoAug 26, 2026
Conversation
…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
|
@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! 🚀 |
Contributor
|
Thanks for the contribution here — squash-merging this now. Any follow-ups we'll track in a fresh issue. 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Fixes a crash-on-startup bug where every
ConduitClient-based example failed immediately becauseConduitClient's constructor unconditionally instantiatedFactoryModule, which throws whenconfig.factoryAddressis absent.Related Issue
Closes #428
Changes
Core SDK
src/client.tsfactoryfrom an eagerly-initialisedreadonlyfield to a lazy getter.FactoryModuleis now only constructed on the first access of.factory, so callers that never use factory queries (stream-only consumers, read-only listing viastreams.list, etc.) are not forced to supplyfactoryAddress. Accessing.factorywithout afactoryAddressstill throwsFactoryModule's clear, actionable error — but now at the call site rather than in the constructor.Examples
examples/create-stream.tsFACTORY_ADDRESSfrom env, validates it is set, and passes it toConduitClient. Updated run-command comment.examples/withdraw.tsexamples/list-streams.tsexamples/nextjs-app/lib/conduit.tsgetFactoryAddress()that readsFACTORY_ADDRESS(server-only env var) and threads it into theConduitClientconfig insidegetClient().examples/nextjs-app/.env.exampleFACTORY_ADDRESSvariable with an explanation of what it is and why it is notNEXT_PUBLIC_-prefixed.Verification Results
new ConduitClient({ network: 'testnet', keypair })does not throwclient.factorywithoutfactoryAddressstill throws a clear errornew ConduitClient(…)lineFACTORY_ADDRESSfrom envexamples/nextjs-appgetClient()passesfactoryAddressgetFactoryAddress()helper added and threaded inFACTORY_ADDRESSin examples gives a clear error message