Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

npci-payment-xdr-sdk

stellar38Apache-2.03.3.0TypeScript support: included

stellar-sdk is a library for working with the Stellar Horizon server.

stellar

readme

Stellar
Creating equitable access to the global financial system

js-stellar-sdk

Build Status Coverage Status

js-stellar-sdk is a Javascript library for communicating with a Stellar Horizon server. It is used for building Stellar apps either on Node.js or in the browser.

It provides:

  • a networking layer API for Horizon endpoints.
  • facilities for building and signing transactions, for communicating with a Stellar Horizon instance, and for submitting transactions or querying network history.

stellar-sdk vs stellar-base

stellar-sdk is a high-level library that serves as client-side API for Horizon. stellar-base is lower-level library for creating Stellar primitive constructs via XDR helpers and wrappers.

Most people will want stellar-sdk instead of stellar-base. You should only use stellar-base if you know what you're doing!

If you add stellar-sdk to a project, do not add stellar-base! Mis-matching 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.

Warning! Node version of stellar-base (stellar-sdk dependency) package is using ed25519 package, a native implementation of Ed25519 in Node.js, as an optional dependency. This means that if for any reason installation of this package fails, stellar-base (and stellar-sdk) will fallback to the much slower implementation contained in tweetnacl.

If you are using stellar-sdk/stellar-base in a browser you can ignore this. However, for production backend deployments you should definitely be using ed25519. If ed25519 is successfully installed and working StellarSdk.FastSigning variable will be equal true. Otherwise it will be false.

Quick start

Using npm to include js-stellar-sdk in your own project:

npm install --save stellar-sdk

Alternatively, you can use jsDelivr or cdnjs in a browser

<script src="https://cdn.jsdelivr.net/npm/stellar-sdk@latest/lib/index.min.js"></script>
`

Install

To use as a module in a Node.js project

  1. Install it using npm:
npm install --save stellar-sdk
  1. require/import it in your JavaScript:
var StellarSdk = require('stellar-sdk');

Help! I'm having trouble installing the SDK on Windows

Unfortunately, the Stellar platform development team mostly works on OS X and Linux, and so sometimes bugs creep through that are specific to windows. When installing stellar-sdk on windows, you might see an error that looks similar to the following:

error MSB8020: The build tools for v120 (Platform Toolset = 'v120 ') cannot be found. To build using the v120 build tools, please install v120 build tools.  Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution"

To resolve this issue, you should upgrade your version of nodejs, node-gyp and then re-attempt to install the offending package using npm install -g --msvs_version=2015 ed25519. Afterwards, retry installing stellar-sdk as normal.

If you encounter the error: "failed to find C:\OpenSSL-Win64", You need to install OpenSSL. More information about this issue can be found here.

In the event the above does not work, please join us on our community slack to get help resolving your issue.

To self host for use in the browser

  1. Install it using bower:
bower install stellar-sdk
  1. Include it in the browser:
<script src="./bower_components/stellar-sdk/stellar-sdk.js"></script>
<script>
  console.log(StellarSdk);
</script>

If you don't want to use install Bower, you can copy built JS files from the bower-js-stellar-sdk repo.

To use the cdnjs hosted script in the browser

  1. Instruct the browser to fetch the library from cdnjs, a 3rd party service that hosts js libraries:
<script src="https://cdnjs.cloudflare.com/ajax/libs/stellar-sdk/{version}/stellar-sdk.js"></script>
<script>
  console.log(StellarSdk);
</script>

Note that this method relies using a third party to host the JS library. This may not be entirely secure.

Make sure that you are using the latest version number. They can be found on the releases page in Github.

To develop and test js-stellar-sdk itself

  1. Clone the repo:
git clone https://github.com/stellar/js-stellar-sdk.git
  1. Install dependencies inside js-stellar-sdk folder:
cd js-stellar-sdk
npm install
  1. Install Node 10.16.3

Because we support earlier versions of Node, please install and develop on Node 10.16.3 so you don't get surprised when your code works locally but breaks in CI.

Here's out to install nvm if you haven't: https://github.com/creationix/nvm

nvm install

# if you've never installed 10.16.3 before you'll want to re-install yarn
npm install -g yarn

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

  1. Observe the project's code style

While you're making changes, make sure to run the linter-watcher to catch any linting errors (in addition to making sure your text editor supports ESLint)

node_modules/.bin/gulp watch
`

If you're working on a file not in src, limit your code to Node 6.16 ES! See what's supported here: https://node.green/ (The reason is that our npm library must support earlier versions of Node, so the tests need to run on those versions.)

How to use with React-Native

  1. Add the following postinstall script:
    yarn rn-nodeify --install url,events,https,http,util,stream,crypto,vm,buffer --hack --yarn
  2. yarn add -D rn-nodeify
  3. Uncomment require('crypto') on shim.js
  4. react-native link react-native-randombytes
  5. Create file rn-cli.config.js
    module.exports = {
    resolver: {
     extraNodeModules: require("node-libs-react-native"),
    },
    };
  6. Add import "./shim"; to the top of index.js
  7. yarn add stellar-sdk

There is also a sample that you can follow.

Usage

For information on how to use js-stellar-sdk, take a look at the Developers site.

There is also API Documentation here.

Testing

To run all tests:

gulp test

To run a specific set of tests:

gulp test:node
gulp test:browser

To generate and check the documentation site:

# install the `serve` command if you don't have it already
npm install -g serve

# generate the docs files
npm run docs

# get these files working in a browser
cd jsdoc && serve .

# you'll be able to browse the docs at http://localhost:5000

Documentation

Documentation for this repo lives in Developers site.

Contributing

For information on how to contribute, please refer to our contribution guide.

Publishing to npm

npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease]

A new version will be published to npm and Bower by Travis CI.

npm >=2.13.0 required. Read more about npm version.

License

js-stellar-sdk is licensed under an Apache-2.0 license. See the LICENSE file for details.

changelog

Changelog

A breaking change will get clearly marked in this log.

Unreleased

v3.3.0

Deprecated ⚠️

  • Horizon 0.25.0 will change the data type for multiple attributes from Int64 to string. When the JSON payload includes an Int64, there are scenarios where large number data can be incorrectly parsed, since JavaScript doesn't support Int64 values. You can read more about it in #1363.

    This release extends the data types for the following attributes to be of type string or number:

    • EffectRecord#offer_id
    • EffectRecord#new_seq
    • OfferRecord#id
    • TradeAggregationRecord#timestamp
    • TradeAggregationRecord#trade_count
    • ManageOfferOperationResponse#offer_id
    • PassiveOfferOperationResponse#offer_id

    We recommend you update your code to handle both string or number in the fields listed above, so that once Horizon 0.25.0 is released, your application will be able to handle the new type without breaking.

v3.2.0

Add ➕

  • Add fee_charged an max_fee to TransactionResponse interface. (455)

Deprecated ⚠️

  • Horizon 0.25 will stop sending the property fee_paid in the transaction response. Use fee_charged and max_fee, read more about it in 450.

v3.1.2

Change

  • Upgrade stellar-base to v2.1.2. (452)

v3.1.1

Change ⚠️

  • Change arguments on server.strictReceivePaths since we included destinationAccount as an argument, but it is not longer required by Horizon. (477)

v3.1.0

Add ➕

  • Add server.strictReceivePaths which adds support for /paths/strict-receive. (444) This function takes a list of source assets or a source address, a destination address, a destination asset and a destination amount.

    You can call it passing a list of source assets:

    server.strictReceivePaths(sourceAssets,destinationAsset, destinationAmount)

    Or a by passing a Stellar source account address:

    server.strictReceivePaths(sourceAccount,destinationAsset, destinationAmount)

    When you call this function with a Stellar account address, it will look at the account’s trustlines and use them to determine all payment paths that can satisfy the desired amount.

  • Add server.strictSendPaths which adds support for /paths/strict-send. (444) This function takes the asset you want to send, and the amount of that asset, along with either a list of destination assets or a destination address.

    You can call it passing a list of destination assets:

    server.strictSendPaths(sourceAsset, sourceAmount, [destinationAsset]).call()

    Or a by passing a Stellar account address:

    server.strictSendPaths(sourceAsset, sourceAmount, "GDRREYWHQWJDICNH4SAH4TT2JRBYRPTDYIMLK4UWBDT3X3ZVVYT6I4UQ").call()

    When you call this function with a Stellar account address, it will look at the account’s trustlines and use them to determine all payment paths that can satisfy the desired amount.

Deprecated ⚠️

v3.0.1

Add

  • Add join method to call builder. (#436)

v3.0.0

BREAKING CHANGES ⚠

  • Drop Support for Node 6 since it has been end-of-lifed and no longer in LTS. We now require Node 10 which is the current LTS until April 1st, 2021. (#424

v2.3.0

Add

  • Add feeStats support. (#409)

Fix

  • Fix Util.verifyChallengeTx documentation (#405)
  • Fix: listen to stream events with addEventListener (#408)

v2.2.3

Fix

  • Fix ServerApi's OrderbookRecord type (#401)

Set

  • Set name in custom errors (#403)

v2.2.2

Fix

  • Fix manage data value in SEP0010 challenge builder. (#396)

Add

  • Add support for networkPassphrase in SEP0010 challenge builder. (#397)

v2.2.1

Fix

  • Fix #391: Remove instance check for MessageEvent on stream error. (#392)

v2.2.0

Add

  • Add helper Utils.verifyChallengeTx to verify SEP0010 "Challenge" Transaction. (#388)
  • Add helper Utils.verifyTxSignedBy to verify that a transaction has been signed by a given account. (#388)

Fix

  • Check for a global EventSource before deciding what to use. This allows you to inject polyfills in other environments like react-native. (#389)

v2.1.1

Fix

  • Fix CallBuilder onmessage type (#385)

v2.1.0

Add

  • Add single script to build docs and call it when combined with jsdoc. (#380)
  • Add SEP0010 transaction challenge builder. (#375)
  • Add home_domain to ServerApi.AccountRecord (#376)

Bump

  • Bump stellar-base to 1.0.3. (#378)
  • Bump @stellar/tslint-config (#377)

Fix

  • Fix jsdoc's build in after_deploy (#373)
  • Create new URI instead of passing serverUrl (Fix #379). (#382)

v2.0.1

  • Breaking change Port stellar-sdk to Typescript. Because we use a slightly different build process, there could be some unanticipated bugs. Additionally, some type definitions have changed:
    • Types that were once in the Server namespace but didn't actually deal with the Server class have been broken out into a new namespace, ServerApi. So, for example, Server.AccountRecord -> ServerApi.AccountRecord.
    • Server.AccountResponse is out of the Server namespace -> AccountResponse
    • Server.*CallBuilder is out of the Server namespace -> *CallBuilder
    • HorizonResponseAccount is now Horizon.AccountResponse
  • Upgrade Webpack to v4.
  • Add support for providing app name and version to request headers.
  • (NPM wouldn't accept the 2.0.0 version, so we're publishing to 2.0.1.)

Many thanks to @Ffloriel and @Akuukis for their help with this release!

v1.0.5

  • Make CallCollectionFunction return a CollectionPage.
  • Update Horizon.AccountSigner[] types.

v1.0.4

  • Automatically tag alpha / beta releases as "next" in NPM.

v1.0.3

  • Upgrade axios to 0.19.0 to close a security vulnerability.
  • Some type fixes.

v1.0.2

  • Upgrade stellar-base to v1.0.2 to fix a bug with the browser bundle.

v1.0.1

  • Upgrade stellar-base to v1.0.1, which makes available again the deprecated operation functions Operation.manageOffer and Operation.createPassiveOffer (with a warning).
  • Fix the documentation around timebounds.

v1.0.0

  • Upgrade stellar-base to v1.0.0, which introduces two breaking changes.
  • Switch stellar-sdk's versioning to true semver! 🎉

v0.15.4

  • Add types for LedgerCallBuilder.ledger.
  • Add types for Server.operationFeeStats.
  • Add types for the HorizonAxiosClient export.
  • Move @types/* from devDependencies to dependencies.
  • Pass and use a stream response type to CallBuilders if it's different from the normal call response.
  • Upgrade stellar-base to a version that includes types, and remove @types/stellar-base as a result.

v0.15.3

  • In .travis.yml, try to switch from the encrypted API key to an environment var.

v0.15.2

  • Fix Server.transactions and Server.payments definitions to properly return collections
  • Renew the npm publish key

v0.15.1

  • Add Typescript type definitions (imported from DefinitelyTyped).
  • Make these changes to those definitions:
    • Add definitions for Server.fetchBaseFee and Server.fetchTimebounds
    • CallBuilder: No long always returns CollectionPaged results. Interfaces that extend CallBuilder should specify whether their response is a collection or not
    • CallBuilder: Add inflation_destination and last_modified_ledger property
    • OfferRecord: Fix the returned properties
    • TradeRecord: Fix the returned properties
    • TradesCallBuilder: Add forAccount method
    • TransactionCallBuilder: Add includeFailed method
    • Horizon.BalanceLineNative/Asset: Add buying_liabilities / selling_liabilities properties
  • Fix documentation links.

v0.15.0

  • Breaking change: stellar-sdk no longer ships with an EventSource polyfill. If you plan to support IE11 / Edge, please use event-source-polyfill to set window.EventSource.
  • Upgrade stellar-base to a version that doesn't use the crypto library, fixing a bug with Angular 6
  • Add Server.prototype.fetchTimebounds, a helper function that helps you set the timebounds property when initting TransactionBuilder. It bases the timebounds on server time rather than local time.

v0.14.0

  • Updated some out-of-date dependencies
  • Update documentation to explicitly set fees
  • Add Server.prototype.fetchBaseFee, which devs can use to fetch the current base fee; we plan to add more functions to help suggest fees in future releases
  • Add includeFailed to OperationCallBuilder for including failed transactions in calls
  • Add operationFeeStats to Server for the new fee stats endpoint
  • After submitting a transaction with a manageOffer operation, return a new property offerResults, which explains what happened to the offer. See Server.prototype.submitTransaction for documentation.

0.13.0

  • Update stellar-base to 0.11.0
  • Added ESLint and Prettier to enforce code style
  • Upgraded dependencies, including Babel to 6
  • Bump local node version to 6.14.0

0.12.0

  • Update stellar-base to 0.10.0:
    • Breaking change Added TransactionBuilder.setTimeout method that sets timebounds.max_time on a transaction. Because of the distributed nature of the Stellar network it is possible that the status of your transaction will be determined after a long time if the network is highly congested. If you want to be sure to receive the status of the transaction within a given period you should set the TimeBounds with maxTime on the transaction (this is what setTimeout does internally; if there's minTime set but no maxTime it will be added). Call to TransactionBuilder.setTimeout is required if Transaction does not have max_time set. If you don't want to set timeout, use TimeoutInfinite. In general you should set TimeoutInfinite only in smart contracts. Please check TransactionBuilder.setTimeout docs for more information.
    • Fixed decoding empty homeDomain.
  • Add offset parameter to TradeAggregationCallBuilder to reflect new changes to the endpoint in horizon-0.15.0

0.11.0

  • Update js-xdr (by updating stellar-base) to support unmarshaling non-utf8 strings.
  • String fields returned by Operation.fromXDRObject() are of type Buffer now (except SetOptions.home_domain and ManageData.name - both required to be ASCII by stellar-core).

0.10.3

  • Update stellar-base and xdr files.

0.10.2

  • Update stellar-base (and js-xdr).

0.10.1

  • Update stellar-base to 0.8.1.

0.10.0

  • Update stellar-base to 0.8.0 with bump_sequence support.

0.9.2

  • Removed .babelrc file from the NPM package.

0.9.1

Breaking changes

  • stellar-sdk is now using native Promise instead of bluebird. The catch function is different. Instead of:

    .catch(StellarSdk.NotFoundError, function (err) { /* ... */ })

    please use the following snippet:

    .catch(function (err) {
      if (err instanceof StellarSdk.NotFoundError) { /* ... */ }
    })
  • We no longer support IE 11, Firefox < 42, Chrome < 49.

Changes

  • Fixed _ is undefined bug.
  • Browser build is around 130 KB smaller!

0.8.2

0.8.1

  • Add an allowed trade aggregation resolution of one minute
  • Various bug fixes
  • Improved documentation

0.8.0

  • Modify /trades endpoint to reflect changes in horizon.
  • Add /trade_aggregations support.
  • Add /assets support.

0.7.3

  • Upgrade stellar-base.

0.7.2

  • Allow hex string in setOptions signers.

0.7.1

  • Upgrade stellar-base.

0.7.0

  • Support for new signer types: sha256Hash, preAuthTx.
  • StrKey helper class with strkey encoding related methods.
  • Removed deprecated methods: Keypair.isValidPublicKey (use StrKey), Keypair.isValidSecretKey (use StrKey), Keypair.fromSeed, Keypair.seed, Keypair.rawSeed.
  • Breaking changes:
    • Network must be explicitly selected. Previously testnet was a default network.
    • Operation.setOptions() method signer param changed.
    • Keypair.fromAccountId() renamed to Keypair.fromPublicKey().
    • Keypair.accountId() renamed to Keypair.publicKey().
    • Dropping support for End-of-Life node versions.

0.6.2

  • Updated stellar.toml location

0.6.1

  • forUpdate methods of call builders now accept strings and numbers.
  • Create a copy of attribute in a response if there is a link with the same name (ex. transaction.ledger, transaction._links.ledger).

0.6.0

  • Breaking change CallBuilder.stream now reconnects when no data was received for a long time. This is to prevent permanent disconnects (more in: #76). Also, this method now returns close callback instead of EventSource object.
  • Breaking change Server.loadAccount now returns the AccountResponse object.
  • Breaking change Upgraded stellar-base to 0.6.0. ed25519 package is now an optional dependency. Check StellarSdk.FastSigning variable to check if ed25519 package is available. More in README file.
  • New StellarTomlResolver class that allows getting stellar.toml file for a domain.
  • New Config class to set global config values.

0.5.1

  • Fixed XDR decoding issue when using firefox

0.5.0

  • Breaking change Server and FederationServer constructors no longer accept object in serverUrl parameter.
  • Breaking change Removed AccountCallBuilder.address method. Use AccountCallBuilder.accountId instead.
  • Breaking change It's no longer possible to connect to insecure server in Server or FederationServer unless allowHttp flag in opts is set.
  • Updated dependencies.

0.4.3

  • Updated dependency (stellar-base).

0.4.2

  • Updated dependencies.
  • Added tests.
  • Added CHANGELOG.md file.

0.4.1

  • stellar-base bump. (c90c68f)

0.4.0

  • Breaking change Bumped stellar-base to 0.5.0. (b810aef)