Skip to content

Fix JavaScript payment event decoding for plain i128 amounts - #3205

Open
RekklesNA wants to merge 1 commit into
stellar:mainfrom
RekklesNA:fix/3188-stellar-plain-transfer-amount
Open

RekklesNA wants to merge 1 commit into
stellar:mainfrom
RekklesNA:fix/3188-stellar-plain-transfer-amount

Conversation

@RekklesNA

Copy link
Copy Markdown

Fixes #3188.

The JavaScript payment monitor reads amount from every decoded transfer value. A transfer without a multiplexed ID carries the amount as a plain i128, which the SDK decodes to a bigint. Reading amount from that value returns undefined, and the example logs a decoding error.

Read the decoded bigint directly and keep reading amount from the map when a multiplexed ID is present. This matches the Python example on the same page.

Verification

Ran the amount-decoding block from the guide before and after the patch with XDR values encoded and decoded by @stellar/[email protected].

Transfer value Before After
Plain i128 with amount 12345678 Logs a decoding error with a TypeError Amount: 12345678 stroops (1.2345678 XLM)
Map with amount: 12345678 and to_muxed_id: 42 Amount: 12345678 stroops (1.2345678 XLM) Amount: 12345678 stroops (1.2345678 XLM)
Reproduce with the JavaScript SDK

Install @stellar/[email protected] in a scratch directory and save the following as repro.mjs there. Run node repro.mjs <path-to-send-and-receive-payments.mdx> against the base and patched guide.

import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import * as sdk from "@stellar/stellar-sdk";

const guide = readFileSync(process.argv[2], "utf8");
const start = guide.indexOf("// Decode transfer amount from the event data");
const end = guide.indexOf("// Decode asset from topics[3]", start);
assert.ok(start >= 0 && end > start);
const run = new Function("StellarSdk", "event", "console", guide.slice(start, end));

const { ScMapEntry, ScVal } = sdk.xdr;
const amount = sdk.nativeToScVal(12345678n, { type: "i128" });
const muxed = ScVal.scvMap([
  new ScMapEntry({ key: ScVal.scvSymbol("amount"), val: amount }),
  new ScMapEntry({
    key: ScVal.scvSymbol("to_muxed_id"),
    val: sdk.nativeToScVal(42n, { type: "u64" }),
  }),
]);

for (const [name, value] of [["plain i128", amount], ["muxed map", muxed]]) {
  console.log(name);
  run(sdk, { value: ScVal.fromXDR(value.toXDR()) }, console);
}

The repository's MDX formatting, component padding, generated RPC docs, Mintlify build, and link checks passed. On Windows, the component padding check was run in batches to stay within the command-line length limit.

@mintlify

mintlify Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 5170678.

Approve preview

@stellar-doxie

stellar-doxie Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

🤖 Automated message from Doxie.

I saw this new PR. I have not reviewed it, because nobody with permission has called me in.

How to reach me:

  • Anyone with write permission can call me in with a /triage comment or the bot:take label.
  • The PR author can send me away with /triage stop. People with write permission can also add the bot:hands-off label.
  • A review request to a maintainer does not call me in. It asks for their judgment.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

send-and-receive-payments: JavaScript event monitor fails on a transfer without a muxed ID

1 participant