Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: Switch to a network and client param solution #1748

Merged
merged 3 commits into from
Oct 25, 2024

Conversation

janniks
Copy link
Collaborator

@janniks janniks commented Oct 21, 2024

This PR was published to npm with the version 6.14.1-pr.78+8cf2e30c
e.g. npm install @stacks/[email protected]+8cf2e30c --save-exact

  • another pivot on network params

The previous solution had some confusing aspects. E.g when using devnet (which is only a URL, and otherwise not different from testnet)

Now, all functions that need fetch, can take a network param to specify which URL+fetchFn to use. All of these function ALSO take the new client param. But it's okay to supply network, client, both or neither. Stacks.js will default to mainnet or infer which network to use. This way we can easily override URL for APIs, but also create manageable network objects that can be passed around everywhere (what people do currently in Stacks.js code).

Want to create your custom network?

const network = {
  ...STACKS_TESTNET,
  chainId: 666,
  client: { baseUrl: "node6.org" }
}

makeSTXTokenTransfer({ network, // ...

Override things if you want for client stuff.

makeSTXTokenTransfer({
  network,
  client: { baseUrl: "node7.com" } // client overrides client in network
  // ...

This also makes it easier to combine network and API/RPC clients.

const client = createClient();

makeSTXTokenTransfer({
  client, // objects are mostly compatible

This way we always know if a function does something with it's fetching/client -- e.g.

selectStxDerivation({
  network,
  // doesn't take `client` param, we know it doesn't do networking

Copy link

vercel bot commented Oct 21, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
stacksjs-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 25, 2024 7:00pm

Copy link

codecov bot commented Oct 21, 2024

Copy link
Member

@zone117x zone117x left a comment

Choose a reason for hiding this comment

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

Solid solution 👍

Base automatically changed from 10-18-fix_remove_legacy_methods to next October 25, 2024 18:54
@janniks janniks force-pushed the 10-21-fix_switch_to_a_network_and_client_param_solution branch from 8cf2e30 to d753ab2 Compare October 25, 2024 18:55
@janniks janniks merged commit 4ef795b into next Oct 25, 2024
1 of 3 checks passed
@janniks janniks deleted the 10-21-fix_switch_to_a_network_and_client_param_solution branch October 25, 2024 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants