Repository navigation
Description
What version are you using?
stellar-cli 28.1.0.
What did you do?
I wanted to preview what a contract call would change before submitting it. I funded two testnet accounts and simulated a native XLM transfer between them without sending it:
Setup:
stellar network use testnet
stellar keys generate alice --fund
stellar keys generate bob --fund
stellar keys use alice
Run:
stellar contract invoke --id native --send=no -- \
transfer --from alice --to bob --amount 10000000
What did you expect to see?
The state changes the call would make, readable alongside the events, without leaving the CLI, in an accessible form like XDR-JSON.
For comparison, the same preview in js-stellar-sdk is a few lines. Calling a method on a contract.Client simulates it without submitting, and the whole simulation response is on the result:
const transfer = await client.transfer({ from: ALICE, to: BOB, amount: 10_000_000n });
humanizeEvents(transfer.simulation.events); // events
transfer.simulation.stateChanges; // created/updated/deleted entries, with before and afterWhat did you see instead?
Only the events from --send=no. The state changes are available only as base64 XDR in --very-verbose trace output, or by building the transaction and calling the RPC directly with curl and jq.
Output:
📅 CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC - Success - Event: TransferWithAmountOnly (transfer), from: "GC6N…VHCV", to: "GASO…EJNSB", sep0011_asset: "native", amount: "10000000"
The events are there, but nothing shows which ledger entries the call would change. I then tried the same command with --very-verbose. The state changes do appear, but only in the trace log of the raw SimulateTransactionResponse, as a Rust Debug structure and then internal base64 XDR components:
state_changes: Some(
[
Updated {
key: "AAAAAAAAAAAk7oDdgCz7ukuBgaxQssJwCurroTdIKsmMWBbRLzh6RA==",
before: "AEunowAAAAAAAAAAJO6A3YAs+7pLgYGsULLCcArq66E3SCrJjFgW0S84ekQAAAAXSHbo...",
after: "AAAAAAAAAAAAAAAAJO6A3YAs+7pLgYGsULLCcArq66E3SCrJjFgW0S84ekQAAAAXSQ9+...",
},
...
To read them I had to manually copy out each value then decode each value separately with stellar xdr decode --type LedgerKey|LedgerEntry.
The only way I found to get the state changes in a readable form was to leave the CLI: build the transaction with --build-only, post it to the RPC's simulateTransaction method with curl and xdrFormat: "json", then filter the response with a jq expression that has to know the shape of each kind of ledger entry. I wrote this up in a docs guide, and that section shows how much is involved: https://github.com/stellar/stellar-docs/pull/2891/changes#diff-b712bd6b822a5e36d3625f575eba3948c8ffcdba41cfafcf0b6a519ec1cd5bfcR105-R167
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsBacklog (Not Ready)
Activity