docs(network): add createNetwork and API key configuration guide - #1865
Open
Dark-Brain07 wants to merge 3 commits into
Open
docs(network): add createNetwork and API key configuration guide#1865Dark-Brain07 wants to merge 3 commits into
Dark-Brain07 wants to merge 3 commits into
Conversation
…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.)
There was a problem hiding this comment.
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/StacksMocknetclass examples withSTACKS_MAINNET/STACKS_TESTNET/etc. constants and string network names. - Adds a comprehensive
createNetworksection covering basic usage,apiKeyshorthand and options form, customhost/httpHeader, custombaseUrl/fetch, plus a warning about the string-name gotcha that drops API key config inbroadcastTransaction. - Updates middleware examples to import from
@stacks/common, usesfetchNonceinstead ofgetNonce, adds a "Checking Network Type" example viatransactionVersion, and adds a comparison table forcreateNetworkvs 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 }); |
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.
Closes #1844
The
@stacks/networkREADME was outdated, still referencing the removed class-based API (StacksMainnet,StacksTestnet, etc.) from pre-v7.Description
Rewrites the
@stacks/networkREADME to document the current API surface:createNetwork()with all overload signaturesapiKeyoption)x-api-keyheadersbroadcastTransactioninstead of the network objecthostmatching andhttpHeaderconfiguration examplesSTACKS_MAINNET,fetchNonce, etc.)createNetworkvs string network namesnew StacksMainnet()) with the current constant-based approachBreaking change?
No breaking changes. Documentation only.
Example
N/A — This is a documentation update.
Checklist