From 4bee9a96d8cc1ed7ee09a520723f24eb39d5ac7b Mon Sep 17 00:00:00 2001 From: Elliot Date: Wed, 1 Jul 2026 16:05:21 -0500 Subject: [PATCH 1/4] chore(sdk-examples): update Java examples for java-stellar-sdk 3.1.0 Standing-correctness audit against java-stellar-sdk 3.1.0. The 1.0.0 package/builder reorg left several examples using classes and builders that no longer exist at the referenced locations (verified against the 3.1.0 source tree). Import package root is unchanged (`org.stellar.sdk`); only the moved classes and the removed nested builders were updated. - invoke-contract-tx-sdk.mdx & stellar-transaction.mdx: exceptions moved to `org.stellar.sdk.exception.*`, `InvokeHostFunctionOperation` to `org.stellar.sdk.operations.*`; `SorobanRpcErrorResponse` was renamed to `SorobanRpcException` (in `org.stellar.sdk.exception`). Updated the imports and the `throws` clauses. - control-asset-access.mdx: `Transaction.Builder` -> `TransactionBuilder` (which requires `setBaseFee`/`setTimeout`); nested `SetOptionsOperation.Builder().setSetFlags(...)` -> Lombok `SetOptionsOperation.builder().setFlags(...)`; imported the operation from `org.stellar.sdk.operations`. - create-account.mdx: nested `CreateAccountOperation.Builder(id, "5")` -> `CreateAccountOperation.builder().destination(id) .startingBalance(new BigDecimal("5"))`; `Asset.createNonNative` -> `Asset.createNonNativeAsset`; added the operations and BigDecimal imports. Co-Authored-By: Claude Opus 4.8 (1M context) --- docs/build/guides/transactions/create-account.mdx | 6 ++++-- .../guides/transactions/invoke-contract-tx-sdk.mdx | 10 +++++----- .../contract-interactions/stellar-transaction.mdx | 10 +++++----- docs/tokens/control-asset-access.mdx | 9 ++++++--- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/docs/build/guides/transactions/create-account.mdx b/docs/build/guides/transactions/create-account.mdx index fbd6e9e17..5952d0b9f 100644 --- a/docs/build/guides/transactions/create-account.mdx +++ b/docs/build/guides/transactions/create-account.mdx @@ -487,10 +487,12 @@ func check(err error) { import java.io.IOException; import java.net.URI; import java.net.http.*; +import java.math.BigDecimal; import java.time.Duration; import java.util.Collections; import org.stellar.sdk.*; +import org.stellar.sdk.operations.*; import org.stellar.sdk.requests.sorobanrpc.*; import org.stellar.sdk.xdr.*; @@ -530,7 +532,7 @@ public final class main { Transaction transaction = new TransactionBuilder(parentAccount, Network.TESTNET) .setBaseFee(Transaction.MIN_BASE_FEE) .setTimeout(TransactionBuilder.TIMEOUT_INFINITE) - .addOperation(new CreateAccountOperation.Builder(child.getAccountId(), "5").build()) + .addOperation(CreateAccountOperation.builder().destination(child.getAccountId()).startingBalance(new BigDecimal("5")).build()) .build(); transaction.sign(parent); @@ -545,7 +547,7 @@ public final class main { log("Balance for account %s", parent.getAccountId()); log("XLM: %d", nativeBalance); - AssetTypeCreditAlphaNum12 usdcAsset = Asset.createNonNative("USDC", TESTNET_USDC_ISSUER); + AssetTypeCreditAlphaNum12 usdcAsset = Asset.createNonNativeAsset("USDC", TESTNET_USDC_ISSUER); long trustlineBalance = getTrustlineBalance(parent.getAccountId(), usdcAsset); log("USDC trustline balance (raw): %d", trustlineBalance); } diff --git a/docs/build/guides/transactions/invoke-contract-tx-sdk.mdx b/docs/build/guides/transactions/invoke-contract-tx-sdk.mdx index 91aaf9105..3cb55e56b 100644 --- a/docs/build/guides/transactions/invoke-contract-tx-sdk.mdx +++ b/docs/build/guides/transactions/invoke-contract-tx-sdk.mdx @@ -236,16 +236,16 @@ Please go to [the project homepage](https://github.com/lightsail-network/java-st ::: ```java -import org.stellar.sdk.AccountNotFoundException; -import org.stellar.sdk.InvokeHostFunctionOperation; import org.stellar.sdk.KeyPair; import org.stellar.sdk.Network; -import org.stellar.sdk.PrepareTransactionException; import org.stellar.sdk.SorobanServer; import org.stellar.sdk.Transaction; import org.stellar.sdk.TransactionBuilder; import org.stellar.sdk.TransactionBuilderAccount; -import org.stellar.sdk.requests.sorobanrpc.SorobanRpcErrorResponse; +import org.stellar.sdk.exception.AccountNotFoundException; +import org.stellar.sdk.exception.PrepareTransactionException; +import org.stellar.sdk.exception.SorobanRpcException; +import org.stellar.sdk.operations.InvokeHostFunctionOperation; import org.stellar.sdk.responses.sorobanrpc.GetTransactionResponse; import org.stellar.sdk.responses.sorobanrpc.SendTransactionResponse; import org.stellar.sdk.scval.Scv; @@ -256,7 +256,7 @@ import java.io.IOException; import java.util.List; public class Example { - public static void main(String[] args) throws SorobanRpcErrorResponse, IOException, InterruptedException { + public static void main(String[] args) throws SorobanRpcException, IOException, InterruptedException { // The source account will be used to sign and send the transaction. KeyPair sourceKeypair = KeyPair.fromSecretSeed("SAAPYAPTTRZMCUZFPG3G66V4ZMHTK4TWA6NS7U4F7Z3IMUD52EK4DDEV"); diff --git a/docs/learn/fundamentals/contract-development/contract-interactions/stellar-transaction.mdx b/docs/learn/fundamentals/contract-development/contract-interactions/stellar-transaction.mdx index b98aa1834..d195176e4 100644 --- a/docs/learn/fundamentals/contract-development/contract-interactions/stellar-transaction.mdx +++ b/docs/learn/fundamentals/contract-development/contract-interactions/stellar-transaction.mdx @@ -217,16 +217,16 @@ print(result) ```java import java.io.IOException; -import org.stellar.sdk.AccountNotFoundException; -import org.stellar.sdk.InvokeHostFunctionOperation; import org.stellar.sdk.KeyPair; import org.stellar.sdk.Network; -import org.stellar.sdk.PrepareTransactionException; import org.stellar.sdk.SorobanServer; import org.stellar.sdk.Transaction; import org.stellar.sdk.TransactionBuilder; import org.stellar.sdk.TransactionBuilderAccount; -import org.stellar.sdk.requests.sorobanrpc.SorobanRpcErrorResponse; +import org.stellar.sdk.exception.AccountNotFoundException; +import org.stellar.sdk.exception.PrepareTransactionException; +import org.stellar.sdk.exception.SorobanRpcException; +import org.stellar.sdk.operations.InvokeHostFunctionOperation; import org.stellar.sdk.responses.sorobanrpc.GetTransactionResponse; import org.stellar.sdk.responses.sorobanrpc.SendTransactionResponse; import org.stellar.sdk.scval.Scv; @@ -234,7 +234,7 @@ import org.stellar.sdk.xdr.TransactionMeta; public class SorobanExample { public static void main(String[] args) - throws SorobanRpcErrorResponse, IOException, InterruptedException { + throws SorobanRpcException, IOException, InterruptedException { // The source account will be used to sign and send the transaction. KeyPair sourceKeypair = diff --git a/docs/tokens/control-asset-access.mdx b/docs/tokens/control-asset-access.mdx index 206a090e8..29381d2bb 100644 --- a/docs/tokens/control-asset-access.mdx +++ b/docs/tokens/control-asset-access.mdx @@ -150,6 +150,7 @@ server ```java import org.stellar.sdk.*; import org.stellar.sdk.Network; +import org.stellar.sdk.operations.SetOptionsOperation; import org.stellar.sdk.responses.AccountResponse; Server server = new Server("https://horizon-testnet.stellar.org"); @@ -159,12 +160,14 @@ KeyPair issuingKeys = KeyPair .fromSecretSeed("SCZANGBA5YHTNYVVV4C3U252E2B6P6F5T3U6MM63WBSBZATAQI3EBTQ4"); AccountResponse sourceAccount = server.accounts().account(issuingKeys.getAccountId()); -Transaction setAuthorization = new Transaction.Builder(sourceAccount, Network.TESTNET) - .addOperation(new SetOptionsOperation.Builder() - .setSetFlags( +Transaction setAuthorization = new TransactionBuilder(sourceAccount, Network.TESTNET) + .addOperation(SetOptionsOperation.builder() + .setFlags( AccountFlag.AUTH_REQUIRED_FLAG.getValue() | AccountFlag.AUTH_REVOCABLE_FLAG.getValue()) .build()) + .setBaseFee(Transaction.MIN_BASE_FEE) + .setTimeout(300) .build(); setAuthorization.sign(issuingKeys); server.submitTransaction(setAuthorization); From 6e0e5c11f3d9cc3bba909cf5c8c690b2299d768e Mon Sep 17 00:00:00 2001 From: Elliot Date: Wed, 1 Jul 2026 16:45:14 -0500 Subject: [PATCH 2/4] chore(sdk-examples): migrate how-to-issue-an-asset Java examples to 3.1.0 Follow-up to the java-stellar-sdk 3.1.0 audit: this file's five Java snippets still used the pre-1.0.0 API (verified against the 3.1.0 source tree). - `new Transaction.Builder(acct, net)` -> `new TransactionBuilder(...)`, which requires an explicit base fee/timeout, so added `.setBaseFee(Transaction.MIN_BASE_FEE)` (and `.setTimeout` where the runnable snippets lacked it). - Nested operation builders replaced with Lombok `builder()`: `ChangeTrustOperation` (asset is now `ChangeTrustAsset`, limit is `BigDecimal`), `PaymentOperation` (amount is `BigDecimal`), `SetOptionsOperation` (`setMasterKeyWeight` -> `masterKeyWeight`). - Per-operation source: `.setSourceAccount(id)` -> `.sourceAccount(id)`. - `SetTrustLineFlagsOperation` was renamed `SetTrustlineFlagsOperation`; the removed `.setAuthorized(true)` convenience is now `.setFlags(EnumSet.of(TrustLineFlags.AUTHORIZED_FLAG))`. Co-Authored-By: Claude Opus 4.8 (1M context) --- docs/tokens/how-to-issue-an-asset.mdx | 59 +++++++++++++++------------ 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/docs/tokens/how-to-issue-an-asset.mdx b/docs/tokens/how-to-issue-an-asset.mdx index efed52d9e..57e044720 100644 --- a/docs/tokens/how-to-issue-an-asset.mdx +++ b/docs/tokens/how-to-issue-an-asset.mdx @@ -246,12 +246,15 @@ transaction = ( Server server = new Server("https://horizon-testnet.stellar.org"); AccountResponse distributorAccount = server.accounts().account(distributorKeypair.getAccountId()); -Transaction transaction = new Transaction.Builder(distributorAccount, Network.TESTNET) +Transaction transaction = new TransactionBuilder(distributorAccount, Network.TESTNET) .addOperation( - new ChangeTrustOperation.Builder(astroDollar, "1000") - .setSourceAccount(distributorKeypair.getAccountId()) + ChangeTrustOperation.builder() + .asset(new ChangeTrustAsset(astroDollar)) + .limit(new BigDecimal("1000")) + .sourceAccount(distributorKeypair.getAccountId()) .build() ) + .setBaseFee(Transaction.MIN_BASE_FEE) .setTimeout(100) .build(); ``` @@ -322,15 +325,14 @@ transaction = ( ```java // We're using TransactionBuilder(...) as a short-hand here // to show that these operations can be "chained" together. -Transaction transaction = new Transaction.Builder(...) - .addOperation(new PaymentOperation.Builder( - distributorKeypair.getAccountId(), - astroDollar, - "1000" - ) - .setSourceAccount( - issuerKeypair.getAccountId() - ) +Transaction transaction = new TransactionBuilder(...) + .addOperation(PaymentOperation.builder() + .destination(distributorKeypair.getAccountId()) + .asset(astroDollar) + .amount(new BigDecimal("1000")) + .sourceAccount( + issuerKeypair.getAccountId() + ) ``` ```go @@ -393,10 +395,11 @@ lock_account_transaction = ( ``` ```java -Transaction lockAccountTransaction = new Transaction.Builder(...) - .addOperation(new SetOptionsOperation.Builder() - .setMasterKeyWeight(0) - .setSourceAccount(issuerKeypair.getAccountId()) +Transaction lockAccountTransaction = new TransactionBuilder(...) + .addOperation(SetOptionsOperation.builder() + .masterKeyWeight(0) + .sourceAccount(issuerKeypair.getAccountId()) + .build() ) ``` @@ -460,11 +463,13 @@ transaction = ( ```java AccountResponse issuerAccount = server.accounts().account(issuerKeys.getAccountId()); -Transaction transaction = new Transaction.Builder(...) - .addOperation(new SetTrustLineFlagsOperation.Builder( - distributorKeys.getAccountId(), - astroDollar - ).setAuthorized(true).build()) +Transaction transaction = new TransactionBuilder(...) + .addOperation(SetTrustlineFlagsOperation.builder() + .trustor(distributorKeys.getAccountId()) + .asset(astroDollar) + .setFlags(EnumSet.of(TrustLineFlags.AUTHORIZED_FLAG)) + .build()) + .setBaseFee(Transaction.MIN_BASE_FEE) .setTimeout(100) .build(); ``` @@ -644,20 +649,24 @@ Asset astroDollar = Asset.createNonNativeAsset("AstroDollar", issuerKeys.getAcco // First, the receiving account must trust the asset AccountResponse receiving = server.accounts().account(receivingKeys.getAccountId()); -Transaction allowAstroDollars = new Transaction.Builder(receiving, Network.TESTNET) +Transaction allowAstroDollars = new TransactionBuilder(receiving, Network.TESTNET) .addOperation( // The `ChangeTrust` operation creates (or alters) a trustline // The second parameter limits the amount the account can hold - new ChangeTrustOperation.Builder(astroDollar, "1000").build()) + ChangeTrustOperation.builder().asset(new ChangeTrustAsset(astroDollar)).limit(new BigDecimal("1000")).build()) + .setBaseFee(Transaction.MIN_BASE_FEE) + .setTimeout(180) .build(); allowAstroDollars.sign(receivingKeys); server.submitTransaction(allowAstroDollars); // Second, the issuing account actually sends a payment using the asset AccountResponse issuer = server.accounts().account(issuerKeys.getAccountId()); -Transaction sendAstroDollars = new Transaction.Builder(issuer, Network.TESTNET) +Transaction sendAstroDollars = new TransactionBuilder(issuer, Network.TESTNET) .addOperation( - new PaymentOperation.Builder(receivingKeys.getAccountId(), astroDollar, "10").build()) + PaymentOperation.builder().destination(receivingKeys.getAccountId()).asset(astroDollar).amount(new BigDecimal("10")).build()) + .setBaseFee(Transaction.MIN_BASE_FEE) + .setTimeout(180) .build(); sendAstroDollars.sign(issuerKeys); server.submitTransaction(sendAstroDollars); From eeb63804448352d3db9db15ef2d456f3c01707df Mon Sep 17 00:00:00 2001 From: Elliot Date: Thu, 2 Jul 2026 09:01:23 -0500 Subject: [PATCH 3/4] chore(sdk-examples): migrate publishing-asset-info Java example to 3.1.0 Addresses review feedback: this file was missed in the initial audit and still used the pre-1.0.0 API. Migrated the SetOptions/home-domain snippet: `new Transaction.Builder(...)` -> `new TransactionBuilder(...)` (with the now-required base fee/timeout), and nested `new SetOptionsOperation.Builder().setHomeDomain(...)` -> Lombok `SetOptionsOperation.builder().homeDomain(...)`. Verified via a full docs/ sweep that no other Java example still uses the old Transaction.Builder / *Operation.Builder / setSourceAccount API. Co-Authored-By: Claude Opus 4.8 (1M context) --- docs/tokens/publishing-asset-info.mdx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/tokens/publishing-asset-info.mdx b/docs/tokens/publishing-asset-info.mdx index d9da6e7b8..82fa1c74e 100644 --- a/docs/tokens/publishing-asset-info.mdx +++ b/docs/tokens/publishing-asset-info.mdx @@ -239,9 +239,11 @@ KeyPair issuingKeys = KeyPair .fromSecretSeed("SCZANGBA5YHTNYVVV4C3U252E2B6P6F5T3U6MM63WBSBZATAQI3EBTQ4"); AccountResponse sourceAccount = server.accounts().account(issuingKeys.getAccountId()); -Transaction setHomeDomain = new Transaction.Builder(sourceAccount, Network.TESTNET) - .addOperation(new SetOptionsOperation.Builder() - .setHomeDomain("yourdomain.com").build()) +Transaction setHomeDomain = new TransactionBuilder(sourceAccount, Network.TESTNET) + .addOperation(SetOptionsOperation.builder() + .homeDomain("yourdomain.com").build()) + .setBaseFee(Transaction.MIN_BASE_FEE) + .setTimeout(180) .build(); setHomeDomain.sign(issuingKeys); server.submitTransaction(setHomeDomain); From 83617efbc68ffb00e5304c83cee12f65700b2a00 Mon Sep 17 00:00:00 2001 From: Elliot Date: Thu, 2 Jul 2026 09:05:46 -0500 Subject: [PATCH 4/4] chore(sdk-examples): address Java PR review feedback - create-account.mdx: `Asset.createNonNativeAsset(...)` returns `org.stellar.sdk.Asset`, and USDC is a 4-char code, so the `AssetTypeCreditAlphaNum12` declaration was both wrong and wouldn't compile (narrowing from `Asset`). Typed the variable as `Asset`, which is also what the `getTrustlineBalance` helper accepts. - how-to-issue-an-asset.mdx: the PaymentOperation "chaining" short-hand left `addOperation(...)` unclosed and the operation un-built; closed the operation with `.build()` and balanced the parentheses. Co-Authored-By: Claude Opus 4.8 (1M context) --- docs/build/guides/transactions/create-account.mdx | 2 +- docs/tokens/how-to-issue-an-asset.mdx | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/build/guides/transactions/create-account.mdx b/docs/build/guides/transactions/create-account.mdx index 5952d0b9f..ceb65abba 100644 --- a/docs/build/guides/transactions/create-account.mdx +++ b/docs/build/guides/transactions/create-account.mdx @@ -547,7 +547,7 @@ public final class main { log("Balance for account %s", parent.getAccountId()); log("XLM: %d", nativeBalance); - AssetTypeCreditAlphaNum12 usdcAsset = Asset.createNonNativeAsset("USDC", TESTNET_USDC_ISSUER); + Asset usdcAsset = Asset.createNonNativeAsset("USDC", TESTNET_USDC_ISSUER); long trustlineBalance = getTrustlineBalance(parent.getAccountId(), usdcAsset); log("USDC trustline balance (raw): %d", trustlineBalance); } diff --git a/docs/tokens/how-to-issue-an-asset.mdx b/docs/tokens/how-to-issue-an-asset.mdx index 57e044720..d154bd605 100644 --- a/docs/tokens/how-to-issue-an-asset.mdx +++ b/docs/tokens/how-to-issue-an-asset.mdx @@ -330,9 +330,8 @@ Transaction transaction = new TransactionBuilder(...) .destination(distributorKeypair.getAccountId()) .asset(astroDollar) .amount(new BigDecimal("1000")) - .sourceAccount( - issuerKeypair.getAccountId() - ) + .sourceAccount(issuerKeypair.getAccountId()) + .build()) ``` ```go