You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
js-stellar-sdk is a JavaScript library for communicating with a
17
18
[Stellar Horizon server](https://github.com/stellar/go/tree/master/services/horizon) and [Soroban RPC](https://soroban.stellar.org/docs/reference/rpc).
18
-
It is used for building Stellar apps either on Node.js or in the browser.
19
+
It is used for building Stellar apps either on Node.js or in the browser, though it can be used in other environments with some tinkering.
19
20
20
21
It provides:
21
22
22
-
- a networking layer API for Horizon endpoints (REST-based) and Soroban RPC (JSON-RPC-based).
23
+
- a networking layer API for Horizon endpoints (REST-based),
24
+
- a networking layer for Soroban RPC (JSONRPC-based).
23
25
- facilities for building and signing transactions, for communicating with a
24
26
Stellar Horizon instance, and for submitting transactions or querying network
25
27
history.
26
28
27
-
### stellar-sdk vs stellar-base
28
-
29
-
`stellar-sdk` is a high-level library that serves as client-side API for Horizon and Soroban RPC, while [stellar-base](https://github.com/stellar/js-stellar-base) is lower-level library for creating Stellar primitive constructs via XDR helpers and wrappers.
30
-
31
-
**Most people will want stellar-sdk instead of stellar-base.** You should only
32
-
use stellar-base if you know what you're doing!
33
-
34
-
If you add `stellar-sdk` to a project, **do not add `stellar-base`!** Mis-matching
35
-
versions could cause weird, hard-to-find bugs. `stellar-sdk` automatically
36
-
installs `stellar-base` and exposes all of its exports in case you need them.
29
+
**Jump to:**
37
30
38
-
> **Important!** The Node.js version of the `stellar-base` (`stellar-sdk` dependency) package
39
-
> uses the [`sodium-native`](https://www.npmjs.com/package/sodium-native) package as
40
-
> an [optional dependency](https://docs.npmjs.com/files/package.json#optionaldependencies). `sodium-native` is
41
-
> a low level binding to [libsodium](https://github.com/jedisct1/libsodium),
42
-
> (an implementation of [Ed25519](https://ed25519.cr.yp.to/) signatures).
43
-
> If installation of `sodium-native` fails, or it is unavailable, `stellar-base` (and `stellar-sdk`) will
44
-
> fallback to using the [`tweetnacl`](https://www.npmjs.com/package/tweetnacl) package implementation.
45
-
>
46
-
> If you are using `stellar-sdk`/`stellar-base` in a browser you can ignore
47
-
> this. However, for production backend deployments you should be
48
-
> using `sodium-native`. If `sodium-native` is successfully installed and working the
49
-
> `StellarSdk.FastSigning` variable will return `true`.
31
+
*[Installation](#installation): details on hitting the ground running
32
+
*[Usage](#usage): links to documentation and a variety of workarounds for non-traditional JavaScript environments
Note that this method relies using a third party to host the JS library. This may not be entirely secure. You can self-host it via [Bower](http://bower.io):
102
69
103
-
### To use the [cdnjs](https://cdnjs.com/libraries/stellar-sdk) hosted script in the browser
70
+
```shell
71
+
bower install @stellar/stellar-sdk
72
+
```
104
73
105
-
1. Instruct the browser to fetch the library from
106
-
[cdnjs](https://cdnjs.com/libraries/stellar-sdk), a 3rd party service that
Because we support the oldest maintenance version of Node, please install and develop on Node 18 so you don't get surprised when your code works locally but breaks in CI.
140
-
141
-
Here's how to install `nvm` if you haven't: https://github.com/creationix/nvm
142
-
143
-
```shell
144
-
nvm install
145
-
146
-
# if you've never installed 16 before you'll want to re-install yarn
147
-
npm install -g yarn
148
-
```
149
-
150
-
If you work on several projects that use different Node versions, you might it
151
-
helpful to install this automatic version manager:
152
-
https://github.com/wbyoung/avn
83
+
If you don't want to use or install Bower, you can copy the packaged JS files from the [Bower repo](https://github.com/stellar/bower-js-stellar-sdk), or just build the package yourself locally (see [Developing :arrow_right: Building](#building)) and copy the bundle.
153
84
154
-
4. Observe the project's code style
85
+
| Always make sure that you are using the latest version number. They can be found on the [releases page](https://github.com/stellar/js-stellar-sdk/releases) in GitHub. |
86
+
|----|
155
87
156
-
While you're making changes, make sure to run the linter to catch any linting
157
-
errors (in addition to making sure your text editor supports ESLint)
158
-
159
-
```shell
160
-
yarn fmt
161
-
```
88
+
## Usage
162
89
90
+
The usage documentation for this library lives in a handful of places:
163
91
164
-
## Usage
92
+
* across the [Stellar Developer Docs](), which includes tutorials and examples,
93
+
* within [this repository itself](https://github.com/stellar/js-stellar-sdk/blob/master/docs/reference/readme.md), and
94
+
* on the generated [API doc site](https://stellar.github.io/js-stellar-sdk/).
165
95
166
-
For information on how to use js-stellar-sdk, take a look at [the
167
-
documentation](https://stellar.github.io/js-stellar-sdk/), or [the
Both `eventsource` (needed for streaming) and `axios` (needed for making HTTP requests) are problematic dependencies in the CFW environment. The experimental branch [`make-eventsource-optional`](https://github.com/stellar/js-stellar-sdk/pull/901) is an attempt to resolve these issues.
149
+
150
+
It requires the following additional tweaks to your project:
151
+
* the `axios-fetch-adapter` lets you use `axios` with `fetch` as a backend, which is available to CF workers
152
+
* it only works with `axios@"<= 1.0.0"` versions, so we need to force an override into the underlying dependency
153
+
* and this can be problematic with newer `yarn` versions, so we need to force the environment to use Yarn 1
154
+
155
+
In summary, the `package.json` tweaks look something like this:
All HTTP calls will use `fetch`, now, meaning it should work in the CloudFlare Worker environment.
184
+
185
+
## Developing
186
+
187
+
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.
Because we support the oldest maintenance version of Node, please install and develop on Node 18 so you don't get surprised when your code works locally but breaks in CI.
205
+
206
+
Here's how to install `nvm` if you haven't: https://github.com/creationix/nvm
207
+
208
+
```shell
209
+
nvm install 18
210
+
211
+
# if you've never installed 18 before you'll want to re-install yarn
212
+
npm install -g yarn
213
+
```
214
+
215
+
If you work on several projects that use different Node versions, you might it helpful to install this automatic version manager: https://github.com/wbyoung/avn
216
+
217
+
4. Observe the project's code style
218
+
219
+
While you're making changes, make sure to run the linter to catch any linting
220
+
errors (in addition to making sure your text editor supports ESLint) and conform to the project's code style.
221
+
222
+
```shell
223
+
yarn fmt
224
+
```
225
+
226
+
### Building
227
+
You can build the developer version (unoptimized, commented, with source maps, etc.) or the production bundles:
228
+
229
+
```shell
230
+
yarn build
231
+
# or
232
+
yarn build:prod
233
+
```
234
+
235
+
### Testing
220
236
221
237
To run all tests:
222
238
@@ -229,13 +245,19 @@ To run a specific set of tests:
229
245
```shell
230
246
yarn test:node
231
247
yarn test:browser
248
+
yarn test:integration
232
249
```
233
250
251
+
In order to have a faster test loop, these suite-specific commands **do not** build the bundles first (unlike `yarn test`). If you make code changes, you will need to run `yarn build` (or a subset like `yarn build:node` corresponding to the test suite) before running the tests again to see your changes.
252
+
234
253
To generate and check the documentation site:
235
254
236
255
```shell
237
256
# install the `serve` command if you don't have it already
# you'll be able to browse the docs at http://localhost:5000
247
269
```
248
270
249
-
## Documentation
271
+
### Publishing
272
+
273
+
For information on how to contribute or publish new versions of this software to `npm`, please refer to our [contribution guide](https://github.com/stellar/js-stellar-sdk/blob/master/CONTRIBUTING.md).
For information on how to contribute or publish new versions of this software to `npm`, please refer to our [contribution guide](https://github.com/stellar/js-stellar-sdk/blob/master/CONTRIBUTING.md).
279
+
`stellar-sdk` is a high-level library that serves as client-side API for Horizon and Soroban RPC, while [`stellar-base](https://github.com/stellar/js-stellar-base) is lower-level library for creating Stellar primitive constructs via XDR helpers and wrappers.
280
+
281
+
**Most people will want stellar-sdk instead of stellar-base.** You should only use stellar-base if you know what you're doing!
282
+
283
+
If you add `stellar-sdk` to a project, **do not add `stellar-base`!** Mismatching versions could cause weird, hard-to-find bugs. `stellar-sdk` automatically installs `stellar-base` and exposes all of its exports in case you need them.
284
+
285
+
> **Important!** The Node.js version of the `stellar-base` (`stellar-sdk` dependency) package uses the [`sodium-native`](https://www.npmjs.com/package/sodium-native) package as an [optional dependency](https://docs.npmjs.com/files/package.json#optionaldependencies). `sodium-native` is a low level binding to [libsodium](https://github.com/jedisct1/libsodium), (an implementation of [Ed25519](https://ed25519.cr.yp.to/) signatures).
286
+
> If installation of `sodium-native` fails, or it is unavailable, `stellar-base` (and `stellar-sdk`) will fallback to using the [`tweetnacl`](https://www.npmjs.com/package/tweetnacl) package implementation. If you are using them in a browser, you can ignore this. However, for production backend deployments, you should be using `sodium-native`.
287
+
> If `sodium-native` is successfully installed and working the `StellarSdk.FastSigning` variable will return `true`.
257
288
258
-
## License
289
+
###License
259
290
260
291
js-stellar-sdk is licensed under an Apache-2.0 license. See the
0 commit comments