Skip to content

docs(network): add createNetwork and API key configuration guide - #1865

Open
Dark-Brain07 wants to merge 3 commits into
stx-labs:mainfrom
Dark-Brain07:fix/docs-add-createnetwork-api-key-guide
Open

docs(network): add createNetwork and API key configuration guide#1865
Dark-Brain07 wants to merge 3 commits into
stx-labs:mainfrom
Dark-Brain07:fix/docs-add-createnetwork-api-key-guide

Conversation

@Dark-Brain07

Copy link
Copy Markdown

Closes #1844

The @stacks/network README was outdated, still referencing the removed class-based API (StacksMainnet, StacksTestnet, etc.) from pre-v7.

Description

Rewrites the @stacks/network README to document the current API surface:

  • Documents createNetwork() with all overload signatures
  • Adds comprehensive API key configuration examples (apiKey option)
  • Documents auto-attachment of x-api-key headers
  • Warns about the common gotcha: losing API key config when passing string network names to broadcastTransaction instead of the network object
  • Adds custom host matching and httpHeader configuration examples
  • Updates middleware examples to use the current API (STACKS_MAINNET, fetchNonce, etc.)
  • Adds a comparison table: createNetwork vs string network names
  • Replaces all deprecated class-based examples (new StacksMainnet()) with the current constant-based approach

Breaking change?

No breaking changes. Documentation only.

Example

N/A — This is a documentation update.


Checklist

  • Unit tested updated code paths (docs-only change, no code changes)
  • Tagged 1 of @janniks or @zone117x for review

…cumentation

Closes stx-labs#1844

The @stacks/network README was outdated, still referencing the removed
class-based API (StacksMainnet, StacksTestnet, etc.) from v5.x.

This rewrite:
- Documents the createNetwork() function with all overload signatures
- Adds comprehensive API key configuration examples
- Documents the apiKey option and its auto-attachment of x-api-key headers
- Warns about the common gotcha of losing API key config when passing
  string network names to broadcastTransaction instead of the network object
- Adds custom host matching and httpHeader configuration examples
- Updates middleware examples to use the current API surface
- Adds a comparison table: createNetwork vs string network names
- Replaces all deprecated class-based examples (new StacksMainnet, etc.)
  with the current constant-based approach (STACKS_MAINNET, etc.)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Rewrites the @stacks/network README to replace removed class-based v6 API examples (new StacksMainnet(), getNonce, network.isMainnet(), etc.) with the current v7 object/constant-based API, and adds new documentation for createNetwork and apiKey configuration that addresses the gap described in #1844.

Changes:

  • Replaces StacksMainnet/StacksTestnet/StacksMocknet class examples with STACKS_MAINNET/STACKS_TESTNET/etc. constants and string network names.
  • Adds a comprehensive createNetwork section covering basic usage, apiKey shorthand and options form, custom host/httpHeader, custom baseUrl/fetch, plus a warning about the string-name gotcha that drops API key config in broadcastTransaction.
  • Updates middleware examples to import from @stacks/common, uses fetchNonce instead of getNonce, adds a "Checking Network Type" example via transactionVersion, and adds a comparison table for createNetwork vs string names.

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

// stacks.js functions, which take a StacksNetwork object will use the custom fetchFn
const nonce = await getNonce('SP3FGQ8Z7JY9BWYZ5WM53E0M9NK7WHJF0691NZ159', myMainnet);
// All stacks.js functions that accept a network object will use the custom fetch function
const nonce = await fetchNonce('SP3FGQ8Z7JY9BWYZ5WM53E0M9NK7WHJF0691NZ159', { network });
// stacks.js functions, which take a StacksNetwork object will use the custom fetchFn
const nonce = await getNonce('SP3FGQ8Z7JY9BWYZ5WM53E0M9NK7WHJF0691NZ159', network);
// stacks.js functions that accept a network object will use the custom fetch function
const nonce = await fetchNonce('SP3FGQ8Z7JY9BWYZ5WM53E0M9NK7WHJF0691NZ159', { network });

const fetchFn = createFetchFn({ pre: preMiddleware, post: preMiddleware }); // a middleware can contain `pre`, `post`, or both
const network = new StacksTestnet({ fetchFn });
const fetchFn = createFetchFn({ pre: preMiddleware, post: postMiddleware });
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.

docs: missing guide for createNetwork and API key configuration

2 participants