Skip to content

Fix broken JS SDK code snippets (invalid syntax, missing imports, undefined variables) #17

Description

@kaankacar

Context

An audit of JS SDK content across the docs found snippets that fail if copied as written. Each item below is a concrete fix with an exact location. These are copy-paste bugs, not API staleness; the surrounding pages are otherwise current.

Checklist

docs/data/apis/horizon/api-reference/errors/error-handling.mdx

  • Line 69: let server = sdk.Server("https://horizon-testnet.stellar.org"); uses the pre-v10 constructor without new and without the Horizon namespace. Change to let server = new sdk.Horizon.Server("https://horizon-testnet.stellar.org");
  • Line 97: time.sleep(5 * time.Second); is Go code inside a JS block. Replace with await new Promise((resolve) => setTimeout(resolve, 5000));
  • Line 138: let server = Horizon.Server(...) is missing new. Also normalize the inconsistent sdk. vs StellarSdk. naming across the page's snippets.
  • While in the file, cross-link the SDK error handling guide: https://stellar.github.io/js-stellar-sdk/guides/05-handle-errors/

docs/learn/fundamentals/contract-development/contract-interactions/stellar-transaction.mdx

  • Line 48: rpc as StellarRpc appears inside a CommonJS require() destructure. as aliasing is import-statement syntax; in a destructure it must be rpc: StellarRpc (or convert the block to an ESM import).

docs/learn/fundamentals/contract-development/contract-interactions/transaction-simulation.mdx

  • Line 75 and line 129: const s = Server("https://soroban-testnet.stellar.org"); is missing new.
  • The snippets use BASE_FEE, nativeToScVal, and Address without importing them. Add them to the import statements.

docs/tokens/how-to-issue-an-asset.mdx

  • Line 118: the secret key is wrapped in curly quotes (‘...’), which is a syntax error if copied. Replace with straight quotes.
  • Early snippets on the page use a global StellarSdk with no import shown; add the import * as StellarSdk from "stellar/stellar-sdk"; line (the full sample at the bottom already has it).

docs/build/guides/transactions/path-payments.mdx

  • Line 77: await SERVER.submitTransaction(transaction) references an undefined SERVER. Use the Horizon server variable defined earlier in the snippet.

docs/data/apis/rpc/api-reference/methods/getLedgerEntries.mdx

  • Line 387: const s = new Server(...) with no import shown and no namespace. Show import { Server } from "stellar/stellar-sdk/rpc"; (and the AssetType import used nearby).

Secondary (undefined variables, verify while in the file)

Acceptance criteria

  • Every JS/TS snippet touched parses (paste into a TS playground or run npx tsc --noEmit on extracted snippets).
  • No JS block contains non-JS code.

Demo copy of stellar#2562 (original author: oceans404) — seeded for the triage-agent demo; content unchanged apart from neutralized mentions.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P1Incorrect, misleading, or user-breaking content — fix promptlybugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions