@stellar/stellar-sdk 14.4.3 → 14.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/README.md +150 -0
  2. package/bin/stellar-js +4 -0
  3. package/dist/stellar-sdk-minimal.js +11448 -10313
  4. package/dist/stellar-sdk-minimal.min.js +1 -1
  5. package/dist/stellar-sdk-no-axios.js +7457 -6322
  6. package/dist/stellar-sdk-no-axios.min.js +1 -1
  7. package/dist/stellar-sdk-no-eventsource.js +11595 -10481
  8. package/dist/stellar-sdk-no-eventsource.min.js +1 -1
  9. package/dist/stellar-sdk.js +10645 -9531
  10. package/dist/stellar-sdk.min.js +1 -1
  11. package/lib/bindings/client.d.ts +30 -0
  12. package/lib/bindings/client.js +134 -0
  13. package/lib/bindings/config.d.ts +34 -0
  14. package/lib/bindings/config.js +83 -0
  15. package/lib/bindings/generator.d.ts +176 -0
  16. package/lib/bindings/generator.js +131 -0
  17. package/lib/bindings/index.d.ts +6 -0
  18. package/lib/bindings/index.js +75 -0
  19. package/lib/bindings/sac-spec.d.ts +1 -0
  20. package/lib/bindings/sac-spec.js +7 -0
  21. package/lib/bindings/types.d.ts +66 -0
  22. package/lib/bindings/types.js +184 -0
  23. package/lib/bindings/utils.d.ts +49 -0
  24. package/lib/bindings/utils.js +223 -0
  25. package/lib/bindings/wasm_fetcher.d.ts +25 -0
  26. package/lib/bindings/wasm_fetcher.js +225 -0
  27. package/lib/cli/index.d.ts +2 -0
  28. package/lib/cli/index.js +171 -0
  29. package/lib/cli/util.d.ts +55 -0
  30. package/lib/cli/util.js +254 -0
  31. package/lib/contract/client.js +2 -1
  32. package/lib/horizon/call_builder.js +30 -6
  33. package/lib/horizon/horizon_axios_client.js +1 -1
  34. package/lib/index.d.ts +1 -0
  35. package/lib/index.js +9 -1
  36. package/lib/minimal/bindings/client.d.ts +30 -0
  37. package/lib/minimal/bindings/client.js +134 -0
  38. package/lib/minimal/bindings/config.d.ts +34 -0
  39. package/lib/minimal/bindings/config.js +83 -0
  40. package/lib/minimal/bindings/generator.d.ts +176 -0
  41. package/lib/minimal/bindings/generator.js +131 -0
  42. package/lib/minimal/bindings/index.d.ts +6 -0
  43. package/lib/minimal/bindings/index.js +75 -0
  44. package/lib/minimal/bindings/sac-spec.d.ts +1 -0
  45. package/lib/minimal/bindings/sac-spec.js +7 -0
  46. package/lib/minimal/bindings/types.d.ts +66 -0
  47. package/lib/minimal/bindings/types.js +184 -0
  48. package/lib/minimal/bindings/utils.d.ts +49 -0
  49. package/lib/minimal/bindings/utils.js +223 -0
  50. package/lib/minimal/bindings/wasm_fetcher.d.ts +25 -0
  51. package/lib/minimal/bindings/wasm_fetcher.js +225 -0
  52. package/lib/minimal/cli/index.d.ts +2 -0
  53. package/lib/minimal/cli/index.js +171 -0
  54. package/lib/minimal/cli/util.d.ts +55 -0
  55. package/lib/minimal/cli/util.js +254 -0
  56. package/lib/minimal/contract/client.js +2 -1
  57. package/lib/minimal/horizon/call_builder.js +30 -6
  58. package/lib/minimal/horizon/horizon_axios_client.js +1 -1
  59. package/lib/minimal/index.d.ts +1 -0
  60. package/lib/minimal/index.js +9 -1
  61. package/lib/minimal/rpc/axios.js +1 -1
  62. package/lib/minimal/rpc/server.d.ts +35 -1
  63. package/lib/minimal/rpc/server.js +110 -43
  64. package/lib/minimal/stellartoml/index.d.ts +3 -0
  65. package/lib/no-axios/bindings/client.d.ts +30 -0
  66. package/lib/no-axios/bindings/client.js +134 -0
  67. package/lib/no-axios/bindings/config.d.ts +34 -0
  68. package/lib/no-axios/bindings/config.js +83 -0
  69. package/lib/no-axios/bindings/generator.d.ts +176 -0
  70. package/lib/no-axios/bindings/generator.js +131 -0
  71. package/lib/no-axios/bindings/index.d.ts +6 -0
  72. package/lib/no-axios/bindings/index.js +75 -0
  73. package/lib/no-axios/bindings/sac-spec.d.ts +1 -0
  74. package/lib/no-axios/bindings/sac-spec.js +7 -0
  75. package/lib/no-axios/bindings/types.d.ts +66 -0
  76. package/lib/no-axios/bindings/types.js +184 -0
  77. package/lib/no-axios/bindings/utils.d.ts +49 -0
  78. package/lib/no-axios/bindings/utils.js +223 -0
  79. package/lib/no-axios/bindings/wasm_fetcher.d.ts +25 -0
  80. package/lib/no-axios/bindings/wasm_fetcher.js +225 -0
  81. package/lib/no-axios/cli/index.d.ts +2 -0
  82. package/lib/no-axios/cli/index.js +171 -0
  83. package/lib/no-axios/cli/util.d.ts +55 -0
  84. package/lib/no-axios/cli/util.js +254 -0
  85. package/lib/no-axios/contract/client.js +2 -1
  86. package/lib/no-axios/horizon/call_builder.js +30 -6
  87. package/lib/no-axios/horizon/horizon_axios_client.js +1 -1
  88. package/lib/no-axios/index.d.ts +1 -0
  89. package/lib/no-axios/index.js +9 -1
  90. package/lib/no-axios/rpc/axios.js +1 -1
  91. package/lib/no-axios/rpc/server.d.ts +35 -1
  92. package/lib/no-axios/rpc/server.js +110 -43
  93. package/lib/no-axios/stellartoml/index.d.ts +3 -0
  94. package/lib/no-eventsource/bindings/client.d.ts +30 -0
  95. package/lib/no-eventsource/bindings/client.js +134 -0
  96. package/lib/no-eventsource/bindings/config.d.ts +34 -0
  97. package/lib/no-eventsource/bindings/config.js +83 -0
  98. package/lib/no-eventsource/bindings/generator.d.ts +176 -0
  99. package/lib/no-eventsource/bindings/generator.js +131 -0
  100. package/lib/no-eventsource/bindings/index.d.ts +6 -0
  101. package/lib/no-eventsource/bindings/index.js +75 -0
  102. package/lib/no-eventsource/bindings/sac-spec.d.ts +1 -0
  103. package/lib/no-eventsource/bindings/sac-spec.js +7 -0
  104. package/lib/no-eventsource/bindings/types.d.ts +66 -0
  105. package/lib/no-eventsource/bindings/types.js +184 -0
  106. package/lib/no-eventsource/bindings/utils.d.ts +49 -0
  107. package/lib/no-eventsource/bindings/utils.js +223 -0
  108. package/lib/no-eventsource/bindings/wasm_fetcher.d.ts +25 -0
  109. package/lib/no-eventsource/bindings/wasm_fetcher.js +225 -0
  110. package/lib/no-eventsource/cli/index.d.ts +2 -0
  111. package/lib/no-eventsource/cli/index.js +171 -0
  112. package/lib/no-eventsource/cli/util.d.ts +55 -0
  113. package/lib/no-eventsource/cli/util.js +254 -0
  114. package/lib/no-eventsource/contract/client.js +2 -1
  115. package/lib/no-eventsource/horizon/call_builder.js +30 -6
  116. package/lib/no-eventsource/horizon/horizon_axios_client.js +1 -1
  117. package/lib/no-eventsource/index.d.ts +1 -0
  118. package/lib/no-eventsource/index.js +9 -1
  119. package/lib/no-eventsource/rpc/axios.js +1 -1
  120. package/lib/no-eventsource/rpc/server.d.ts +35 -1
  121. package/lib/no-eventsource/rpc/server.js +110 -43
  122. package/lib/no-eventsource/stellartoml/index.d.ts +3 -0
  123. package/lib/rpc/axios.js +1 -1
  124. package/lib/rpc/server.d.ts +35 -1
  125. package/lib/rpc/server.js +110 -43
  126. package/lib/stellartoml/index.d.ts +3 -0
  127. package/package.json +9 -3
  128. package/CHANGELOG.md +0 -2023
package/README.md CHANGED
@@ -27,6 +27,7 @@ The library provides:
27
27
  - [...with React Native](#usage-with-react-native)
28
28
  - [...with Expo](#usage-with-expo-managed-workflows)
29
29
  - [...with CloudFlare Workers](#usage-with-cloudflare-workers)
30
+ * [CLI](#cli): generate TypeScript bindings for Stellar smart contracts
30
31
  * [Developing](#developing): contribute to the project!
31
32
  * [Understanding `stellar-sdk` vs. `stellar-base`](#stellar-sdk-vs-stellar-base)
32
33
  * [License](#license)
@@ -200,6 +201,155 @@ Horizon.AxiosClient.defaults.adapter = fetchAdapter as any;
200
201
 
201
202
  All HTTP calls will use `fetch`, now, meaning it should work in the CloudFlare Worker environment.
202
203
 
204
+ ## CLI
205
+
206
+ The SDK includes a command-line tool for generating TypeScript bindings from Stellar smart contracts. These bindings provide fully-typed client code with IDE autocompletion and compile-time type checking.
207
+
208
+ ### Running the CLI
209
+
210
+ ```shell
211
+ # Using npx (no installation required)
212
+ npx @stellar/stellar-sdk generate [options]
213
+
214
+ # Or if installed globally
215
+ stellar-js generate [options]
216
+ ```
217
+
218
+ ### Generating Bindings
219
+
220
+ You can generate bindings from three different sources:
221
+
222
+ #### From a local WASM file
223
+
224
+ ```shell
225
+ npx @stellar/stellar-sdk generate \
226
+ --wasm ./path/to/wasm_file/my_contract.wasm \
227
+ --output-dir ./my-contract-client \
228
+ --contract-name my-contract
229
+ ```
230
+
231
+ #### From a WASM hash on the network
232
+
233
+ ```shell
234
+ # testnet, futurenet, and localnet have default RPC URLs
235
+ npx @stellar/stellar-sdk generate \
236
+ --wasm-hash <hex-encoded-hash> \
237
+ --network testnet \
238
+ --output-dir ./my-contract-client \
239
+ --contract-name my-contract
240
+ ```
241
+
242
+ #### From a deployed contract ID
243
+
244
+ ```shell
245
+ npx @stellar/stellar-sdk generate \
246
+ --contract-id CABC...XYZ \
247
+ --network testnet \
248
+ --output-dir ./my-contract-client
249
+ ```
250
+
251
+ #### With custom RPC server options
252
+
253
+ For mainnet or when connecting to RPC servers that require authentication:
254
+
255
+ ```shell
256
+ # Mainnet requires --rpc-url (no default)
257
+ npx @stellar/stellar-sdk generate \
258
+ --contract-id CABC...XYZ \
259
+ --rpc-url https://my-rpc-provider.com \
260
+ --network mainnet \
261
+ --output-dir ./my-contract-client
262
+
263
+ # With custom timeout and headers for authenticated RPC servers
264
+ npx @stellar/stellar-sdk generate \
265
+ --contract-id CABC...XYZ \
266
+ --rpc-url https://my-rpc-server.com \
267
+ --network mainnet \
268
+ --output-dir ./my-contract-client \
269
+ --timeout 30000 \
270
+ --headers '{"Authorization": "Bearer my-token"}'
271
+
272
+ # localnet with default RPC URL auto-enables --allow-http
273
+ npx @stellar/stellar-sdk generate \
274
+ --contract-id CABC...XYZ \
275
+ --network localnet \
276
+ --output-dir ./my-contract-client
277
+
278
+ # When overriding the default URL, you must specify --allow-http if using HTTP
279
+ npx @stellar/stellar-sdk generate \
280
+ --contract-id CABC...XYZ \
281
+ --rpc-url http://my-local-server:8000/rpc \
282
+ --network localnet \
283
+ --output-dir ./my-contract-client \
284
+ --allow-http
285
+ ```
286
+
287
+ ### CLI Options
288
+
289
+ | Option | Description |
290
+ |--------|-------------|
291
+ | `--wasm <path>` | Path to a local WASM file |
292
+ | `--wasm-hash <hash>` | Hex-encoded hash of WASM blob on the network |
293
+ | `--contract-id <id>` | Contract ID of a deployed contract |
294
+ | `--rpc-url <url>` | Stellar RPC server URL (has defaults for testnet/futurenet/localnet, required for mainnet) |
295
+ | `--network <network>` | Network to use: `testnet`, `mainnet`, `futurenet`, or `localnet` (required for network sources) |
296
+ | `--output-dir <dir>` | Output directory for generated bindings (required) |
297
+ | `--contract-name <name>` | Name for the generated package (derived from filename if not provided) |
298
+ | `--overwrite` | Overwrite existing files in the output directory |
299
+ | `--allow-http` | Allow insecure HTTP connections to RPC server (default: false) |
300
+ | `--timeout <ms>` | RPC request timeout in milliseconds |
301
+ | `--headers <json>` | Custom headers as JSON object (e.g., `'{"Authorization": "Bearer token"}'`) |
302
+
303
+ #### Default RPC URLs
304
+
305
+ When using `--network`, the CLI provides default RPC URLs for most networks:
306
+
307
+ | Network | Default RPC URL |
308
+ |---------|-----------------|
309
+ | `testnet` | `https://soroban-testnet.stellar.org` |
310
+ | `futurenet` | `https://rpc-futurenet.stellar.org` |
311
+ | `localnet` | `http://localhost:8000/rpc` (auto-enables `--allow-http` only when using default URL) |
312
+ | `mainnet` | None - you must provide `--rpc-url` ([find providers](https://developers.stellar.org/docs/data/rpc/rpc-providers)) |
313
+
314
+ ### Generated Output
315
+
316
+ The CLI generates a complete npm package structure:
317
+
318
+ ```
319
+ my-contract-client/
320
+ ├── src/
321
+ │ ├── index.ts # Barrel exports
322
+ │ ├── client.ts # Typed Client class with contract methods
323
+ │ └── types.ts # TypeScript interfaces for contract types
324
+ ├── package.json
325
+ ├── tsconfig.json
326
+ ├── README.md
327
+ └── .gitignore
328
+ ```
329
+
330
+ ### Using Generated Bindings
331
+
332
+ After generating, you can use the bindings in your project:
333
+
334
+ ```typescript
335
+ import { Client } from './my-contract-client';
336
+
337
+ const client = new Client({
338
+ contractId: 'CABC...XYZ',
339
+ networkPassphrase: Networks.TESTNET,
340
+ rpcUrl: 'https://soroban-testnet.stellar.org',
341
+ publicKey: keypair.publicKey(),
342
+ ...basicNodeSigner(keypair, Networks.TESTNET),
343
+ });
344
+
345
+ // Fully typed method calls with IDE autocompletion
346
+ const result = await client.transfer({
347
+ from: 'GABC...',
348
+ to: 'GDEF...',
349
+ amount: 1000n,
350
+ });
351
+ ```
352
+
203
353
  ## Developing
204
354
 
205
355
  So you want to contribute to the library: welcome! Whether you're working on a fork or want to make an upstream request, the dev-test loop is pretty straightforward.
package/bin/stellar-js ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+
3
+ // Entry point for the stellar CLI
4
+ require("../lib/cli/index.js").runCli();