Skip to content

Commit 488f385

Browse files
committed
docs: add agent skill for java-stellar-sdk
1 parent 6b7eab4 commit 488f385

15 files changed

Lines changed: 1419 additions & 0 deletions

File tree

.claude-plugin/marketplace.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "lightsail-network",
3+
"owner": {
4+
"name": "lightsail-network"
5+
},
6+
"metadata": {
7+
"description": "Agent skills for the Stellar Java SDK (network.lightsail:stellar-sdk)."
8+
},
9+
"plugins": [
10+
{
11+
"name": "java-stellar-sdk",
12+
"source": "./",
13+
"description": "Teaches AI coding agents how to build Stellar blockchain applications using the Java Stellar SDK: transactions, operations, Horizon API, Soroban smart contracts, XDR/SCVal, and SEP protocols.",
14+
"version": "0.1.0",
15+
"author": {
16+
"name": "overcat"
17+
},
18+
"homepage": "https://github.com/lightsail-network/java-stellar-sdk",
19+
"license": "Apache-2.0",
20+
"category": "development",
21+
"tags": ["stellar", "blockchain", "java", "sdk", "soroban", "agent-skill"]
22+
}
23+
]
24+
}

.claude-plugin/plugin.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "java-stellar-sdk",
3+
"description": "Agent skill that teaches AI coding agents how to build Stellar blockchain applications with the Java Stellar SDK (network.lightsail:stellar-sdk): transactions, operations, Horizon, Soroban, XDR/SCVal, and SEP protocols.",
4+
"version": "0.1.0",
5+
"author": {
6+
"name": "overcat"
7+
},
8+
"homepage": "https://github.com/lightsail-network/java-stellar-sdk",
9+
"license": "Apache-2.0"
10+
}

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Pending
44

55
### Update
6+
- docs: add an [Agent Skill](https://agentskills.io/) for the Java Stellar SDK under `skills/`, plus Claude Code plugin manifests in `.claude-plugin/`. The skill gives AI coding agents concise, Stellar-specific guidance (transactions, operations, Horizon, Soroban, XDR/SCVal, and SEP protocols) when generating application code with `stellar-sdk`.
67
- feat: add SEP-0046, SEP-0047, and SEP-0048 contract introspection support. New `ContractMeta`, `ContractSpec`, and `ContractInfo` wrappers under `org.stellar.sdk.contract` parse contract Wasm metadata and interface specs locally. `SorobanServer` adds `getContractWasm`, `getContractWasmByHash`, `getContractMeta`, `getContractSpec`, and `getContractInfo` for RPC-backed retrieval.
78

89
## 3.0.0

skills/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Agent Skill for the Java Stellar SDK
2+
3+
This directory contains an [Agent Skills](https://agentskills.io/) compatible skill for
4+
developers building Stellar applications in Java with the `stellar-sdk` package
5+
(`network.lightsail:stellar-sdk`).
6+
7+
**Audience: SDK users, not java-stellar-sdk contributors.** The skill is a portable
8+
artifact that can be installed in another project so coding agents have concise,
9+
Stellar-specific guidance while generating application code.
10+
11+
## Contents
12+
13+
```text
14+
skills/java-stellar-sdk/
15+
SKILL.md # entry point: install, conventions, critical rules, examples
16+
references/ # topic-specific reference files loaded on demand
17+
```
18+
19+
The skill is self-contained: examples are embedded directly, and external pointers use
20+
absolute URLs such as the SDK Javadoc and GitHub. It should continue to work after being
21+
copied into a project that does not contain this repository.
22+
23+
## Installation options
24+
25+
| Environment | How to use this skill |
26+
| --- | --- |
27+
| Claude Code plugin | Add this repository as a plugin marketplace and install the `java-stellar-sdk` plugin. The marketplace manifest lives at `.claude-plugin/marketplace.json`. |
28+
| Claude Code project skill | Copy `skills/java-stellar-sdk/` into your project at `.claude/skills/java-stellar-sdk/`. |
29+
| Claude Code personal skill | Copy `skills/java-stellar-sdk/` into `~/.claude/skills/java-stellar-sdk/`. |
30+
| Other Agent Skills compatible tools | Copy `skills/java-stellar-sdk/SKILL.md` and its `references/` directory into the location your tool uses for skills or reusable instructions. |
31+
| Generic coding agents | Point your agent instructions file at `SKILL.md`, or paste the relevant reference file into the agent context. |
32+
33+
For Claude Code's skill and plugin behavior, see the Claude Code documentation for
34+
[skills](https://docs.anthropic.com/en/docs/claude-code/skills) and
35+
[plugin marketplaces](https://docs.anthropic.com/en/docs/claude-code/plugin-marketplaces).
36+
37+
## Discovery and marketplaces
38+
39+
This repository is set up for two broad distribution paths:
40+
41+
- **Claude Code marketplaces:** `.claude-plugin/marketplace.json` describes this repository
42+
as a Claude Code plugin source.
43+
- **Agent Skills indexes and registries:** public directories or aggregators may discover
44+
repositories containing `SKILL.md` files. Examples include community indexes such as
45+
[skillsmp.com](https://skillsmp.com/) and any future Agent Skills compatible catalogs.
46+
47+
Third-party indexes are convenience discovery channels only. They are not required to use
48+
the skill, and their indexing behavior, ranking, and update schedule are outside this
49+
project's control.
50+
51+
## Not shipped via Maven
52+
53+
Adding the `network.lightsail:stellar-sdk` dependency installs the SDK package only. It does
54+
**not** install this skill. Install the skill through a plugin marketplace, by copying this
55+
directory, or by cloning this repository.
56+
57+
## Maintenance
58+
59+
The skill is maintained alongside the SDK so examples and API references can stay in sync.
60+
Keep embedded examples small, explicit, and aligned with the SDK Javadoc. When SDK APIs
61+
change, review `SKILL.md` and the files under `references/` as part of the same change.

skills/java-stellar-sdk/SKILL.md

Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
---
2+
name: java-stellar-sdk
3+
description: Build Stellar blockchain applications in Java using stellar-sdk (network.lightsail:stellar-sdk). Use for transaction building, signing, Horizon queries, Soroban RPC, smart contract deployment/invocation, XDR/SCVal conversion, and SEP integrations.
4+
license: Apache-2.0
5+
compatibility: Published artifacts target Java 8 bytecode (require Java 8+). Building from source requires JDK 21.
6+
metadata:
7+
sdk_package: network.lightsail:stellar-sdk
8+
repository: lightsail-network/java-stellar-sdk
9+
docs: https://javadoc.io/doc/network.lightsail/stellar-sdk
10+
---
11+
12+
# Stellar Java SDK (`network.lightsail:stellar-sdk`)
13+
14+
Write correct Java for the Stellar network using the `stellar-sdk` package. This file is
15+
self-contained; load a file from `references/` only when the task needs that topic.
16+
17+
## Install
18+
19+
Maven:
20+
21+
```xml
22+
<dependency>
23+
<groupId>network.lightsail</groupId>
24+
<artifactId>stellar-sdk</artifactId>
25+
<version>3.0.0</version>
26+
</dependency>
27+
```
28+
29+
Gradle:
30+
31+
```groovy
32+
implementation 'network.lightsail:stellar-sdk:3.0.0'
33+
```
34+
35+
## Import style
36+
37+
Public APIs live under `org.stellar.sdk`; operations under `org.stellar.sdk.operations`;
38+
the contract helpers under `org.stellar.sdk.contract`; SCVal helpers under
39+
`org.stellar.sdk.scval`; exceptions under `org.stellar.sdk.exception`.
40+
41+
```java
42+
import org.stellar.sdk.Asset;
43+
import org.stellar.sdk.KeyPair;
44+
import org.stellar.sdk.Network;
45+
import org.stellar.sdk.Server;
46+
import org.stellar.sdk.Transaction;
47+
import org.stellar.sdk.TransactionBuilder;
48+
import org.stellar.sdk.operations.PaymentOperation;
49+
import org.stellar.sdk.scval.Scv;
50+
```
51+
52+
## Clients
53+
54+
- `Server` — Horizon client. See `references/horizon.md`.
55+
- `SorobanServer` — Soroban RPC client (`Closeable`). See `references/soroban.md`.
56+
- `ContractClient` — high-level Soroban contract client (`Closeable`) that wraps the
57+
simulate → prepare → sign → submit flow. See `references/soroban.md`.
58+
59+
The SDK is **synchronous** (built on OkHttp); there is no separate async client.
60+
61+
## Java conventions (read this first)
62+
63+
These are the things that most often trip people up with *this* SDK:
64+
65+
- **Operations use Lombok builders.** Every operation is built with `XxxOperation.builder()...
66+
.build()`, e.g. `PaymentOperation.builder().destination(d).asset(a).amount(amt).build()`.
67+
`InvokeHostFunctionOperation` instead exposes static factories (see `references/operations.md`).
68+
- **There are three asset types — don't mix them up.** `Asset` (payments, offers, paths),
69+
`ChangeTrustAsset` (the `ChangeTrustOperation` line, wraps an `Asset` or `LiquidityPool`), and
70+
`TrustLineAsset` (balances/trustline entries). See `references/assets.md`.
71+
- **Amounts and balances are `BigDecimal`.** `new BigDecimal("10.5")`, never `double`/`float`.
72+
- **`G...` and `M...` both work as a destination.** Address strings accept plain ed25519
73+
accounts and SEP-23 muxed accounts; use `MuxedAccount` to build/parse `M...` (see
74+
`references/sep.md`).
75+
- **Clients are `Closeable`.** `Server.close()`; wrap `SorobanServer`/`ContractClient` in
76+
try-with-resources. `SSEStream` from `.stream(...)` must also be closed to stop it.
77+
- **SDK exceptions are unchecked.** Everything extends `RuntimeException`
78+
(`org.stellar.sdk.exception.SdkException`), so the compiler will not force you to catch them —
79+
you still should. The common supertype for network/RPC errors is `NetworkException`.
80+
- **`KeyPair.getSecretSeed()` returns `char[]`,** not `String`, so it can be zeroed after use.
81+
- **Android:** works out of the box on API level 28+. For lower levels add the
82+
[Java Stellar SDK Android SPI](https://github.com/lightsail-network/java-stellar-sdk-android-spi).
83+
- **Example syntax.** The SDK runs on **Java 8+**, but the snippets in this skill use some
84+
Java 9–16 conveniences for brevity. On Java 8, substitute equivalents: `List.of(...)`
85+
`Arrays.asList(...)`, `Map.of(...)` → a populated `LinkedHashMap`, `"x".repeat(n)` → a literal,
86+
pattern-matching `instanceof` → a classic cast, and `java.net.http``HttpURLConnection` or
87+
any HTTP client.
88+
89+
## Critical rules (do not violate)
90+
91+
1. **`BigDecimal` amounts, never `double`/`float`.** Use `new BigDecimal("350.1234567")`,
92+
not `350.1234567`. Lumens have 7 decimal places; binary floats lose precision.
93+
2. **Prefer loading secret seeds at runtime** (env / a secret manager) over embedding
94+
them in source: `KeyPair.fromSecretSeed(System.getenv("STELLAR_SECRET_KEY"))`.
95+
3. **Always set a timeout** with `.setTimeout(...)` (or explicit time bounds). A
96+
transaction without one can hang in the pending pool indefinitely.
97+
4. **Use the correct network.** `Network.TESTNET` vs `Network.PUBLIC`. Signatures are
98+
network-specific; a testnet-signed transaction is invalid on mainnet.
99+
5. **`TransactionBuilder.build()` increments the source account's sequence number.** If you
100+
build but do not submit (or submission fails with `tx_bad_seq`), reload the account with
101+
`server.loadAccount(...)` before building again.
102+
6. **For Soroban, prepare before signing.** `sorobanServer.prepareTransaction(tx)` (or
103+
`ContractClient.invoke(...)` which simulates by default) fills in footprint, auth, and
104+
resource fees. Signing before this produces an invalid transaction.
105+
7. **Convert contract args with `Scv.to*`** and read results with `Scv.from*`. Never pass
106+
raw Java values to a contract.
107+
8. **Restore archived state** when simulation reports archived entries (see
108+
`references/soroban.md`).
109+
9. **Close clients.** Call `server.close()` for `Server`; use try-with-resources for
110+
`SorobanServer` and `ContractClient` (both implement `Closeable`).
111+
10. **Catch specific SDK exceptions** (`BadRequestException`, `BadResponseException`,
112+
`PrepareTransactionException`, …) from `org.stellar.sdk.exception`, not a broad
113+
`Exception`. The common supertype is `NetworkException`.
114+
115+
## Minimal end-to-end examples
116+
117+
### 1. Create / load a keypair
118+
119+
```java
120+
import org.stellar.sdk.KeyPair;
121+
122+
// New random account (fund it before use — see example 2).
123+
KeyPair kp = KeyPair.random();
124+
System.out.println(kp.getAccountId()); // G... (safe to share)
125+
System.out.println(kp.getSecretSeed()); // S... (secret — never log or commit in real code)
126+
127+
// Load an existing account from the environment.
128+
KeyPair signer = KeyPair.fromSecretSeed(System.getenv("STELLAR_SECRET_KEY"));
129+
130+
// Verify-only keypair (cannot sign).
131+
KeyPair publicOnly = KeyPair.fromAccountId("GD2JXEFGEO53CNQ22KN2ICOQ2LOASCABQHAIOMLZV265C246PFKKHPYU");
132+
```
133+
134+
### 2. Build, sign, and submit a payment
135+
136+
```java
137+
import java.math.BigDecimal;
138+
import org.stellar.sdk.*;
139+
import org.stellar.sdk.operations.PaymentOperation;
140+
import org.stellar.sdk.responses.TransactionResponse;
141+
142+
KeyPair source = KeyPair.fromSecretSeed(System.getenv("STELLAR_SECRET_KEY"));
143+
String destination = "GD2JXEFGEO53CNQ22KN2ICOQ2LOASCABQHAIOMLZV265C246PFKKHPYU";
144+
145+
Server server = new Server("https://horizon-testnet.stellar.org");
146+
147+
// Reload right before building so the sequence number is current.
148+
TransactionBuilderAccount account = server.loadAccount(source.getAccountId());
149+
150+
PaymentOperation payment =
151+
PaymentOperation.builder()
152+
.destination(destination)
153+
.asset(Asset.createNativeAsset())
154+
.amount(new BigDecimal("350.1234567")) // BigDecimal amount
155+
.build();
156+
157+
Transaction transaction =
158+
new TransactionBuilder(account, Network.TESTNET)
159+
.setBaseFee(Transaction.MIN_BASE_FEE)
160+
.addMemo(Memo.text("Hello, Stellar!"))
161+
.addOperation(payment)
162+
.setTimeout(30)
163+
.build();
164+
165+
transaction.sign(source);
166+
TransactionResponse response = server.submitTransaction(transaction);
167+
System.out.println(response.getHash());
168+
server.close();
169+
```
170+
171+
New testnet accounts can be funded by Friendbot:
172+
`GET https://friendbot.stellar.org?addr=<G...>`.
173+
174+
### 3. Query Horizon
175+
176+
```java
177+
import org.stellar.sdk.Server;
178+
import org.stellar.sdk.requests.RequestBuilder;
179+
import org.stellar.sdk.responses.Page;
180+
import org.stellar.sdk.responses.operations.OperationResponse;
181+
182+
Server server = new Server("https://horizon.stellar.org");
183+
184+
// Request builders are chainable; .execute() runs the HTTP request.
185+
Page<OperationResponse> payments =
186+
server.payments()
187+
.forAccount("GB6NVEN5HSUBKMYCE5ZOWSK5K23TBWRUQLZY3KNMXUZ3AQ2ESC4MY4AQ")
188+
.order(RequestBuilder.Order.DESC)
189+
.limit(10)
190+
.execute();
191+
for (OperationResponse op : payments.getRecords()) {
192+
System.out.println(op.getType());
193+
}
194+
```
195+
196+
### 4. Invoke a Soroban contract (read-only)
197+
198+
For contracts you call repeatedly, prefer **generated typed bindings** (see
199+
`references/bindings.md`). The hand-written form with `ContractClient` is:
200+
201+
```java
202+
import java.util.List;
203+
import org.stellar.sdk.Network;
204+
import org.stellar.sdk.contract.ContractClient;
205+
import org.stellar.sdk.scval.Scv;
206+
import org.stellar.sdk.xdr.SCVal;
207+
208+
// A read-only call needs no signer, but `source` is required and must be an account
209+
// that already exists on the target network — simulate() loads its sequence via
210+
// server.getAccount(), which throws AccountNotFoundException if the account is missing.
211+
String source = "GD2JXEFGEO53CNQ22KN2ICOQ2LOASCABQHAIOMLZV265C246PFKKHPYU";
212+
213+
try (ContractClient client =
214+
new ContractClient(
215+
"CACZTW72246RA2MOCNKUBRRRRPT26UZ7LXE5ZHH44OGKIMCTQJ74O4D5",
216+
"https://soroban-testnet.stellar.org:443",
217+
Network.TESTNET)) {
218+
SCVal result =
219+
client
220+
.invoke("hello", List.of(Scv.toSymbol("world")), source, null, null,
221+
(int) org.stellar.sdk.Transaction.MIN_BASE_FEE)
222+
.result(); // read-only: no signer needed
223+
System.out.println(result);
224+
}
225+
```
226+
227+
For a state-changing call, pass `source` and `signer`, then `signAndSubmit(...)`. See
228+
`references/soroban.md`.
229+
230+
## Reference index
231+
232+
Load on demand:
233+
234+
- `references/quickstart.md` — install → keypair → fund → payment → query → contract.
235+
- `references/transactions.md` — transaction lifecycle, memos, preconditions, fee bump,
236+
multisig, XDR round-trips, sequence-number pitfalls.
237+
- `references/assets.md``Asset` vs `ChangeTrustAsset` vs `TrustLineAsset`, native vs
238+
alphanum4/12, canonical form.
239+
- `references/operations.md` — catalog of every operation and its builder.
240+
- `references/horizon.md` — Horizon client, request builders, pagination, streaming, errors.
241+
- `references/soroban.md` — Soroban RPC client + `ContractClient`/`AssembledTransaction`.
242+
- `references/bindings.md` — generate typed contract clients with `stellar-contract-bindings`.
243+
- `references/xdr_scval.md` — SCVal conversion, `Address`, XDR encode/decode.
244+
- `references/sep.md` — SEP support matrix and common flows (SEP-02/05/10/23/35/45/...).
245+
- `references/troubleshooting.md` — exception hierarchy and common failures.
246+
247+
Full API docs (Javadoc): https://javadoc.io/doc/network.lightsail/stellar-sdk

0 commit comments

Comments
 (0)