Repository navigation
fix(soroban): make the smart-contract cost guide's examples compile on SDK 28 - #2903
Merged
ElliotFriend merged 1 commit intoOct 12, 2026
Merged
Conversation
Seven of the guide's eight full contract examples did not build against soroban-sdk 28.0.0 / stellar-cli 28.1.0, including three of the four blocks the guide presents as the correct pattern (both "Optimal Contract" blocks and the keyed-vecs alternative it recommends). Storage examples: pass keys by reference (`get(&KEY)`); a bare `&str` key fails the `TryFromVal<Env, str>` bound on `Val`; use `Symbol`/`#[contracttype]` keys; unwrap the `Option` that `get` returns; `push_back`, not `push`, on `soroban_sdk::Vec`; `unwrap_or_else(|| Vec::new(&env))`, because `soroban_sdk::Vec<T>` implements neither `Default` nor `FromIterator`, so `unwrap_or_default()` and iterator-chain `.collect()` are both unavailable; add the missing `Vec` import and the `#[contracttype]` attribute on types used as storage values and keys. Token examples: SEP-41 `transfer` takes `to: MuxedAddress`, so the recipient vectors become `Vec<MuxedAddress>` and the contract's own address is converted with `MuxedAddress::from`. CLI guidance: `stellar contract build` optimizes by default in current stellar-cli, so document `--optimize=false` and how to tell which behaviour a version has; `--cost` prints only for a sent transaction, and prints nothing with `--send=no`. Storage prose: temporary entries are not cleared at the end of the invocation — they live until their TTL (testnet `min_temporary_ttl` is 720 ledgers), so the §5 description and one §3 trade-off bullet are wrong, and §5 also contradicted itself. The instance-storage size cap is a validator-set network parameter (testnet `contract_data_entry_size_bytes` is 65,536, not "on the order of 100 KB"), so link the live network limits instead of asserting a number. Both points match how stellar#2880 corrected the sibling storage guide. Also renumber the duplicated "### 5" section and level the two storage-API headings that sat at the same depth as their parent. Closes stellar#1845
Contributor
|
🤖 Automated message from the Stellar Triage Bot. Thanks for the PR. I saw it, but I review only when someone calls me in. How to reach me:
|
Contributor
|
/triage |
Contributor
|
🤖 Automated message from the Stellar Triage Bot. Reviewing because @kaankacar asked with /triage. Verified against the soroban-sdk 28.0.0 and stellar-cli 28.1.0 source. The SDK calls, the
External-origin change, so a maintainer merges this. |
ElliotFriend
approved these changes
Oct 12, 2026
Contributor
|
PR Preview: torn down |
oceans404
added a commit
that referenced
this pull request
Oct 21, 2026
Four conflicts resolved: two storage headings moved down a level with the export's anchor ids kept, and the --optimize and --cost passages taken from upstream with root-relative links. Checks: scope 1 file, all 10 Rust samples identical to main, parity all upstream lines present (6 differ only by heading ids and link format), guard clean, mint validate passed, broken-links at baseline 8, page 200.
ElliotFriend
pushed a commit
that referenced
this pull request
Oct 21, 2026
Port of 902971c to the Mintlify tree. Refs #2903 Co-Authored-By: Claude Opus 5.5 <[email protected]>
ElliotFriend
added a commit
that referenced
this pull request
Oct 22, 2026
) Replaces the Docusaurus site with Mintlify's converted tree (base bcec501), with tooling trimmed to prettier, husky, redocly, the OpenRPC build, and the mint CLI. Commits that landed on main after bcec501 were ported by hand. Ported: Refs #2448 Refs #2671 Refs #2672 Refs #2727 Refs #2827 Refs #2828 Refs #2837 Refs #2856 Refs #2857 Refs #2869 Refs #2871 Refs #2878 Refs #2880 Refs #2881 Refs #2885 Refs #2886 Refs #2890 Refs #2892 Refs #2893 Refs #2895 Refs #2900 Refs #2901 Refs #2902 Refs #2903 Refs #2905 Refs #2912 Refs #2913 Refs #2915 Refs #2918 Refs #2922 Merged into the branch: Refs #2936 Refs #2937 Refs #2938 Refs #2940 Co-authored-by: alexistabak-cpu <[email protected]> Co-authored-by: Emir Ayral <[email protected]> Co-authored-by: John Wooten <[email protected]> Co-authored-by: Kaan Kacar <[email protected]> Co-authored-by: Leigh <[email protected]> Co-authored-by: maz <[email protected]> Co-authored-by: Michael Lip <[email protected]> Co-authored-by: Scopuly <[email protected]> Co-authored-by: stellar-triage-bot[bot] <333411864+stellar-triage-bot[bot]@users.noreply.github.com> Co-authored-by: Steph <[email protected]> Co-authored-by: urvisavla <[email protected]> Co-authored-by: water-k-max <[email protected]> Co-authored-by: Wlademyr Mendes <[email protected]> Co-Authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1845. Part of #1837.
Every Rust block in this guide was extracted with a script and compiled in an
isolated crate against soroban-sdk 28.0.0 / stellar-cli 28.1.0
(
stellar contract build --optimize=false). Before this change, 7 of the 8full-contract examples failed to build; only the "Optimized Using Events"
example compiled. The failures include three of the four blocks the guide
presents as the correct pattern: both "Optimal Contract ✅" blocks and the
"Alternative: using keyed vecs ✅" block it recommends.
What was broken, and why
persistent().get("total_count")Val: TryFromVal<Env, str>not satisfied;strhas no known sizeSymbol/#[contracttype]valuesget(...)result used as the valuecannot add _ to Option<_>,+=onOption<_>,no method push for Optionunwrap_or(...)/unwrap_or_else(...)moves.push(x)on a SorobanVecno method named push found for soroban_sdk::Vec<T>push_back.unwrap_or_default()onVec<Symbol>soroban_sdk::Vec<T>: Defaultnot satisfied.iter().filter().map().collect()Vec<Symbol>: FromIterator<Symbol>not implementedVec::new(&env)struct/enumas a stored value or keyVal: TryFromVal<Env, DataKey>not satisfied#[contracttype]Vec<u32>/Vec<Address>in signaturescannot find type Vec in this scopeVecadded to theuse soroban_sdk::{...}listtoken_client.transfer(&from, recipient, &amt)transfertakesto: MuxedAddress(soroban-sdk-28.0.0/src/token.rs:154)Vec<MuxedAddress>recipients,MuxedAddress::from(...)for the contract itselfCLI wording
stellar contract build --helpon 28.1.0 describes--optimizeas"Enabled by default; pass
--optimize=falseto disable." Measured on thisguide's own kind of contract: 10,067 bytes with
--optimize=false, 8,575bytes with the default build. The guide told readers to add the flag to get
optimization, which is no longer the step that matters.
--costwas described as producing a breakdown for any invoke. It reportswhat the network charged, so it prints the fee table only when a transaction
is sent; with
--send=nothe call is simulated and--costprints nothing.Structure
"### 5. Contract size" duplicated "### 5. Use of appropriate
env.storagemechanisms", and thetemporary()/instance()headings were atthe same level as their parent while
persistent()was one level below it.Verification
Re-extracting the blocks from the edited file and rebuilding each one: all
eight full-contract examples pass. The two remaining ```rust fences are inline
expression fragments (
let mut v1 = alloc::vec![];/ `let mut v2 = [0; 100];`)that are not standalone crates, so they were not compiled.
Formatting:
pnpm exec prettier --config .prettierrc.js -c <file>reports "Allmatched files use Prettier code style!" — re-run after the prose edits, exit 0. I did
not run a full
pnpm build, so I am claiming the file parses and is format-clean, notthat I inspected the rendered page. The three prose changes are a 3/3-line delta that
touches no code fence, so the compile results above still describe the shipped
examples.
Storage prose (§3 bullet, §5)
Three prose lines were changed alongside the code, because
stellar network settings --network testnetand the SDK source contradict them:after each transaction. The SDK's own
temporary()doc says entries are "removedfrom the ledger after their lifetime ends… such as oracle data, claimable
balances, offer", and testnet's
min_temporary_ttlis 720 ledgers (~1 hour at the5 s target close), so they outlive the invocation. §5 also contradicted itself: the
same paragraph said "cleared at the end of the contract invocation" while its
Lifetime bullet said "exists for a predefined period and is then removed".
serialized". It is a validator-set network parameter, and today it is 65,536 bytes
(
contract_data_entry_size_bytes; keys are capped bycontract_data_key_size_bytes= 250). I replaced the number with a link to the live value, which is the pattern
docs: correct storage cost ranking and entry size limit claim #2880 used in
choosing-the-right-storage.mdx.Two nearby claims I left deliberately: "Likely cheaper than storing data separately
in persistent storage" and "does not appear in the ledger footprint" are the SDK's own
wording for
instance(), and "Highest cost compared to others" for persistentmatches the SDK's "the more expensive storage type". They read oddly next to #2880's
persistent/instance "same rent class" table, but that table is about durability while
those sentences are about access pattern, so I did not want to force a rewrite. If
you would rather §5 just defer to
choosing-the-right-storage.mdx, say so and I willswap in a link instead.
Still untouched: the events-vs-storage and batch-vs-loop pricing narrative, and the
"use of built-in tools" section's fee claims. I did not measure those, so I have not
asserted anything about them either way. Happy to open a follow-up issue if useful.