Skip to content

Update JS snippets that use XDR method getters removed in stellar-sdk v17 #3082

Closed

Description

@ElliotFriend

Context

@stellar/stellar-sdk 17 moved its XDR types to plain classes with property access. The method-style getters are gone: union arms (.switch(), .v1(), .contractData(), .accountId()), struct fields (.val(), .key(), .instance(), .claimants()), and enum constructors (xdr.ContractDataDurability.persistent()). Unions now expose .type and .value, struct fields are plain properties, and enum members are properties. See the XDR migration guide.

#2932 fixed this for the fee-payer sorobanData snippets. The JS snippets below still use the old getters and throw ... is not a function on 17.x. Checked against 17.4.0:

FAIL scAddr.switch()          scAddr.switch is not a function
OK   scAddr.type              scAddressTypeAccount
FAIL scAddr.accountId()       scAddr.accountId is not a function
FAIL asset.value.assetCode()  asset.value.assetCode is not a function
OK   asset.value.assetCode    AssetCode4

The other open js-sdk-v17 issues (#2560, #2561, #2562, #2563, #2564, #2965, #2968) don't cover this.

Checklist

Line numbers are pinned to b5f22fb.

  • docs/build/apps/guestbook/frontend.mdx L395-397: message.val.contractData().key() and .contractData().val(). The guestbook template repo has the same code, so keep the two in sync (see Guestbook frontend: use the SDK's token amount helper instead of dividing by 1e7 #2965).
  • docs/build/guides/archival/extend-persistent-entry-js.mdx
    • L159-160: .contractData().val().instance() and instance.executable().wasmHash()
    • L207: the prose names executable().wasmHash() and executable().switch()
  • docs/build/guides/archival/restore-contract-js.mdx L72: entry.val().instance().wasmHash()
  • docs/build/guides/basics/verify-trustlines.mdx L162: entries[0].val.trustLine(), plus any field getters that follow it.
  • docs/build/guides/dapps/state-archival.mdx L338: entry.val().instance().wasmHash()
  • docs/build/guides/rpc/retrieve-contract-code-js.mdx L71-75: .contractData().val().instance().executable().wasmHash()
  • docs/build/guides/transactions/claimable-balances.mdx
    • L190: operationResult.balanceId()
    • L408-418: .val.claimableBalance() and .claimants(), plus the claimant getters inside the loop.
  • docs/build/guides/transactions/clawbacks.mdx
    • L108-113: claimableBalance.claimants()
    • L311: creationResult.balanceId()
  • docs/data/apis/rpc/api-reference/methods/getLedgerEntries.mdx L525, L694, L733-766: .switch(), .val().instance().executable().wasmHash(), .contractData(), .contractCode().code()
  • docs/learn/fundamentals/contract-development/contract-interactions/stellar-transaction.mdx L562: entry.switch()
  • docs/learn/fundamentals/contract-development/storage/state-archival.mdx L371: entry.val().instance().wasmHash()
  • docs/learn/fundamentals/data-format/xdr.mdx L91-147: this is the conceptual section on unions.

Notes for the fix

  • Run each rewritten snippet against @stellar/stellar-sdk 17.x. Don't just pattern-replace: some chains pass through a union (.val on a ledger entry result, then .value for the arm), and the right property path depends on the type.
  • fromXDR still works on 17, so it doesn't need changing in these snippets.
  • Out of scope: docs/data/analytics/hubble/developer-guide/backfill/JS-UDF.mdx uses txe.feeBump().tx(), but it runs against a pinned StellarBase bundle inside a BigQuery UDF, not the current SDK.
  • Also out of scope: Rust env.storage().instance() and Keypair.accountId() calls aren't XDR getters.

Activity

  1. added
    bot:take
    on Nov 9, 2026
  2. stellar-doxie commented on Nov 9, 2026

    @stellar-doxie
    Contributor

    🤖 Automated message from the Stellar Triage Bot.

    Working this because @ElliotFriend added bot:take.

    I am checking each listed snippet against @stellar/stellar-sdk 17.x now. I will report back with a PR or a question.

  3. stellar-doxie commented on Nov 9, 2026

    @stellar-doxie
    Contributor

    🤖 Automated message from the Stellar Triage Bot.

    Working this because @ElliotFriend added bot:take.

    PR #3083 ports every checklist item to @stellar/stellar-sdk 17.x. The checks job passes.

    • I checked each property, arm name and factory against the 17.4.0 typings. I could not run the snippets here.
    • It also fixes the same v17 break on 4 pages the list missed, and the restore snippets, which never put the Wasm code key in the footprint. The PR body lists each one.
    • The guestbook template repo still pins ^16.4.1 and uses the old getters. It needs the same change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bot:takejs-sdk-v17

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions