Skip to content

feat(client): replace NetworkId with Chain descriptor#223

Open
solidsnakedev wants to merge 8 commits intomainfrom
feat/chain-interface
Open

feat(client): replace NetworkId with Chain descriptor#223
solidsnakedev wants to merge 8 commits intomainfrom
feat/chain-interface

Conversation

@solidsnakedev
Copy link
Copy Markdown
Collaborator

The network?: string field on createClient carried a string identifier but left slot timing, network magic, and chain identity as separate concerns that callers had to assemble manually. There was no type that encoded all of these together, and the slotConfig top-level parameter was easy to omit or misconfigure.

This replaces network with a required chain: Chain field. Three built-in constants — mainnet, preprod, preview — are exported from the top-level package. Each constant carries the chain name, id, network magic, slot config, and epoch length in one object. A defineChain helper allows custom chains for local devnets and private forks. The networkId property on returned client objects is replaced with chain. The @evolution-sdk/devnet package gains getChain(cluster) and BOOTSTRAP_CHAIN for test setup.

Copilot AI review requested due to automatic review settings March 31, 2026 23:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR replaces the loosely-typed network (+ separate slotConfig) client configuration with a required chain: Chain descriptor that bundles network identity, network magic, and slot timing parameters into a single object, and updates docs/examples/devnet tooling accordingly.

Changes:

  • Introduces Chain + defineChain, and exports built-in mainnet, preprod, preview constants from the top-level package.
  • Updates createClient and related client types to use chain and to source slot timing directly from chain.slotConfig.
  • Adds devnet helpers (getChain(cluster) and BOOTSTRAP_CHAIN) and migrates several devnet tests/docs/examples to the new API.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/evolution/src/sdk/client/ClientImpl.ts Reworks createClient to require chain and wires chain.slotConfig into tx building.
packages/evolution/src/sdk/client/Client.ts Updates public client types to expose chain instead of networkId where applicable and removes NetworkId type.
packages/evolution/src/sdk/client/Chain.ts Adds the Chain model, defineChain, and built-in chain constants.
packages/evolution/src/index.ts Re-exports chain utilities/constants from the package entrypoint.
packages/evolution-devnet/test/TxBuilder.VoteValidators.test.ts Migrates devnet test setup to use Cluster.getChain(...) / BOOTSTRAP_CHAIN.
packages/evolution-devnet/test/TxBuilder.Validity.test.ts Migrates validity-interval devnet tests to chain API.
packages/evolution-devnet/test/TxBuilder.SpendScriptRef.test.ts Migrates script-ref devnet tests to chain API.
packages/evolution-devnet/test/TxBuilder.PlutusMint.test.ts Migrates Plutus minting devnet tests to chain API.
packages/evolution-devnet/test/TxBuilder.Metadata.test.ts Migrates metadata devnet tests to chain API.
packages/evolution-devnet/test/TxBuilder.Compose.test.ts Migrates compose devnet tests to chain API.
packages/evolution-devnet/test/TxBuilder.Chain.test.ts Migrates chainResult devnet tests to chain API.
packages/evolution-devnet/test/Client.Devnet.test.ts Migrates devnet client test to chain API.
packages/evolution-devnet/src/Cluster.ts Adds getChain(cluster) and BOOTSTRAP_CHAIN to produce Chain descriptors for devnet usage.
examples/with-vite-react/src/components/TransactionBuilder.tsx Updates example app to select a Chain constant and pass it to createClient.
docs/content/docs/clients/providers.mdx Updates provider docs snippets to pass chain: preprod.
docs/content/docs/clients/index.mdx Updates overview docs to describe chain configuration.
docs/content/docs/clients/client-basics.mdx Adds chain configuration section and updates examples to use built-in chain constants.
docs/content/docs/clients/architecture.mdx Updates architecture examples to use chain: mainnet.
.changeset/chain-interface.md Documents the chain migration and the devnet chain helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +839 to 845
// Chain only → MinimalClient
export function createClient(config: { chain: Chain }): MinimalClient

// Implementation signature - handles all cases (all synchronous now)
export function createClient(config?: {
network?: NetworkId
export function createClient(config: {
chain: Chain
provider?: ProviderConfig
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change makes createClient require a chain and removes the optional/no-arg overloads, but there are still call sites in the repo using the old { network, slotConfig } shape and/or createClient() with no args (e.g. docs/app/(home)/page.tsx, packages/evolution-devnet/test/TxBuilder.AddSigner.test.ts, TxBuilder.Governance.test.ts, TxBuilder.Mint.test.ts, TxBuilder.NativeScript.test.ts, TxBuilder.Pool.test.ts, TxBuilder.RedeemerBuilder.test.ts, TxBuilder.ScriptStake.test.ts, TxBuilder.Stake.test.ts, TxBuilder.Vote.test.ts, and .specs/client-module-workflow.md). Those need to be migrated (or the old overload kept) or the build/tests/docs will fail.

Copilot uses AI. Check for mistakes.
Comment on lines +2 to +3
"@evolution-sdk/evolution": patch
"@evolution-sdk/devnet": patch
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changeset marks the release as a patch, but replacing network?: NetworkId with required chain: Chain (and removing createClient() / default-network behavior) is a breaking public API change. The changeset should be a major bump (or at least follow the repo’s documented semver policy for breaking changes).

Suggested change
"@evolution-sdk/evolution": patch
"@evolution-sdk/devnet": patch
"@evolution-sdk/evolution": major
"@evolution-sdk/devnet": major

Copilot uses AI. Check for mistakes.
Comment on lines 49 to 63
@@ -58,13 +59,13 @@ export default function TransactionBuilder() {

const providerConfig = {
type: "blockfrost" as const,
baseUrl: blockfrostUrls[networkId as keyof typeof blockfrostUrls],
baseUrl: blockfrostUrls[networkEnv as keyof typeof blockfrostUrls],
projectId: import.meta.env.VITE_BLOCKFROST_PROJECT_ID || ""
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chain falls back to preprod when networkEnv is not one of the known keys, but providerConfig.baseUrl still indexes blockfrostUrls using networkEnv, which will be undefined in that fallback case. Use the same resolved key used for chain (or derive the URL from chain) so the provider config stays consistent with the chosen chain.

Copilot uses AI. Check for mistakes.
Comment on lines 32 to 39
```typescript
import { mainnet, preprod, preview, defineChain } from "@evolution-sdk/evolution";

createClient({
network: "mainnet" | "preprod" | "preview",
provider?: ProviderConfig, // Optional
wallet?: WalletConfig // Optional
chain: mainnet | preprod | preview, // or a custom chain via defineChain(...)
provider?: ProviderConfig, // Optional
wallet?: WalletConfig // Optional
})
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code sample calls createClient(...) but doesn’t import it (and also references ProviderConfig/WalletConfig without imports). The snippet should include createClient in the import (and either import the types or make the snippet explicitly schematic) so readers can copy/paste it without errors.

Copilot uses AI. Check for mistakes.
- Update wallet guide MDX files (api-wallet, private-key, seed-phrase)
  to use chain constants instead of network strings, fixing twoslash
  build errors (TS2769)
- Migrate all 9 devnet test files from `network: 0` to
  `chain: Cluster.getChain(cluster)` / `Cluster.BOOTSTRAP_CHAIN`,
  fixing TypeError on `chain.id`
- Update Cluster.getSlotConfig JSDoc example
- Regenerate module reference docs
- Replace network: "preprod" / "mainnet" / "preview" with chain: preprod / mainnet / preview
- Replace network: 0 with chain: Cluster.BOOTSTRAP_CHAIN / Cluster.getChain(cluster)
- Add chain constant imports to all twoslash code blocks
- Fix BOOTSTRAP_CHAIN epochLength type (number | undefined -> number)
- Fix as const on chain references in provider-only-client.mdx
- Update migration-from-lucid table and wallets/security guidance

52 docs files + 1 source file updated
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.

2 participants