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

Open
wants to merge 3 commits into
base: 10-18-fix_remove_legacy_methods
Choose a base branch
from

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 21, 2024 3:47pm

@janniks janniks self-assigned this Oct 21, 2024
Copy link

codecov bot commented Oct 21, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 👀 In Review
Development

Successfully merging this pull request may close these issues.

1 participant