• Stars
    star
    606
  • Rank 73,920 (Top 2 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created over 9 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Main Stellar client library for the JavaScript language.
Stellar
Creating equitable access to the global financial system

js-stellar-sdk

npm version Weekly Downloads Test 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.

Important! The Node.js version of the stellar-base (stellar-sdk dependency) package uses the sodium-native package as an optional dependency. sodium-native is a low level binding to libsodium, (an implementation of Ed25519 signatures). If installation of sodium-native fails, or it is unavailable, stellar-base (and stellar-sdk) will fallback to using the tweetnacl package implementation.

If you are using stellar-sdk/stellar-base in a browser you can ignore this. However, for production backend deployments you should be using sodium-native. If sodium-native is successfully installed and working the StellarSdk.FastSigning variable will return true.

Quick start

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

npm install --save stellar-sdk

Alternatively, you can use cdnjs in a browser:

<script src="https://cdnjs.cloudflare.com/ajax/libs/stellar-sdk/{version}/stellar-sdk.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');

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 or 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 14

Because we support the oldest maintenance version of Node, please install and develop on Node 14 so you don't get surprised when your code works locally but breaks in CI.

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

nvm install

# if you've never installed 14 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

Usage

For information on how to use js-stellar-sdk, take a look at the documentation, or the examples.

There is also Horizon REST API Documentation here.

Usage with React-Native

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

There is also a sample that you can follow.

Using in an Expo managed workflow

  1. Install yarn add --dev rn-nodeify
  2. Add the following postinstall script:
yarn rn-nodeify --install process,url,events,https,http,util,stream,crypto,vm,buffer --hack --yarn
  1. Add import "./shim"; to the your app's entry point (by default ./App.js)
  2. yarn add stellar-sdk
  3. expo install expo-random

At this point, the Stellar SDK will work, except that StellarSdk.Keypair.random() will throw an error. To work around this, you can create your own method to generate a random keypair like this:

import * as Random from 'expo-random';
import StellarSdk from 'stellar-sdk';

const generateRandomKeypair = () => {
  const randomBytes = Random.getRandomBytes(32);

  return StellarSdk.Keypair.fromRawEd25519Seed(Buffer.from(randomBytes));
};

Testing

To run all tests:

yarn test

To run a specific set of tests:

yarn test:node
yarn 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
yarn 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 GitHub actions.

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.

More Repositories

1

stellar-core

Reference implementation for the peer-to-peer agent that manages the Stellar network.
C
3,098
star
2

go

Stellar's public monorepo of go code
Go
1,268
star
3

kelp

Kelp is a free and open-source trading bot for the Stellar DEX and 100+ centralized exchanges
Go
1,054
star
4

soroban-example-dapp

End-to-End Example Soroban Dapp
Rust
951
star
5

stellar-protocol

Developer discussion about possible changes to the protocol.
RPC
506
star
6

slingshot

A new blockchain architecture under active development, with a strong focus on scalability, privacy and safety
Rust
403
star
7

stellar-client

INACTIVE. Browser based client for stellard. This repository is inactive. It points to the stellard network, which is being replaced by stellar-core. Please refer to the replacement repository, interstellar-client, which points to the stellar-core network.
JavaScript
306
star
8

dashboard

JavaScript
215
star
9

quickstart

Home of the stellar/quickstart docker image for development and testing
Shell
183
star
10

java-stellar-sdk

Java
173
star
11

awesome-stellar

πŸ‘¨β€πŸš€ A curated list of Stellar applications, blog posts, educational resources, tools, and more.
159
star
12

js-stellar-base

The lowest-level stellar helper library. It consists of classes to read, write, hash, and sign Stellar xdr
JavaScript
103
star
13

stellar-wallet

Holds encrypted data. Used by stellar-client to store the user's key in a secure way.
JavaScript
103
star
14

django-polaris

An extendable Django app for building modular Stellar services
Python
95
star
15

rs-soroban-sdk

Rust SDK for Soroban contracts.
Rust
89
star
16

laboratory

JavaScript
77
star
17

freighter

Stellar chrome extension
TypeScript
72
star
18

new-docs

JavaScript
68
star
19

js-stellar-wallets

A library to make it easier to write wallets that interact with Stellar
TypeScript
62
star
20

rs-soroban-env

Rust environment for Soroban contracts.
Rust
57
star
21

stellar-demo-wallet

Provides a front-end interface to test SEP interoperability. Website at https://demo-wallet.stellar.org/
TypeScript
51
star
22

soroban-cli

CLI for Soroban contracts.
Rust
51
star
23

soroban-docs

Documentation for Soroban
MDX
50
star
24

soroban-examples

Example Soroban Contracts
Rust
47
star
25

packages

SDF - Packages
Shell
46
star
26

paper-wallet

HTML
43
star
27

os-projects

42
star
28

sorobanathon

Sorobanathon: First Light
42
star
29

starlight

Layer 2 payment channel protocol for the Stellar network.
Go
40
star
30

starbridge

Software that facilitates bridge builders who are connecting the Stellar network to other blockchains.
Go
39
star
31

account-viewer-v2

A simple tool to view an account on the Stellar network and make transactions from it.
TypeScript
37
star
32

stellar-docs

Documentation for Stellar
MDX
35
star
33

java-stellar-anchor-sdk

Java SDK for the Stellar network anchor development.
Kotlin
35
star
34

developers

Stellar developer portal site generator.
JavaScript
33
star
35

stellar-etl-airflow

Airflow DAGs for the Stellar ETL project
Python
31
star
36

stellar-disbursement-platform-backend

Stellar Disbursement Platform Backend
Go
28
star
37

stellar-etl

Stellar ETL will enable real-time analytics on the Stellar network
Go
28
star
38

js-xdr

Read/write XDR encoded data structures (RFC 4506)
JavaScript
24
star
39

js-soroban-client

Main Soroban client library for the Javascript language
TypeScript
23
star
40

xdrgen

A code generator for XDR
Rust
22
star
41

stellar-xdr

Staging area for future version of Stellar XDR.
RPC
18
star
42

rs-stellar-xdr

Rust lib for Stellar XDR.
Rust
18
star
43

docs-wallet

SCSS
17
star
44

stellar-disbursement-platform-frontend

Stellar Disbursement Platform Frontend
TypeScript
16
star
45

stellar-turrets

Reference implementation of the Stellar Turrets protocol
JavaScript
15
star
46

stellar-anchor-tests

A library and CLI tool for testing Stellar anchors.
TypeScript
13
star
47

typescript-wallet-sdk

Typescript Wallet SDK to build Stellar wallets
TypeScript
12
star
48

stories

JavaScript
12
star
49

hack-stellar

TypeScript
12
star
50

.github

11
star
51

moneygram-access-wallet-mvp

An MVP wallet integrated with MoneyGram Access
Python
11
star
52

stellar-tutorials

This repository holds tools and tutorials to help developers build on Stellar.
JavaScript
10
star
53

scaffold-soroban

Soroban example dapps
JavaScript
10
star
54

hackathon-get-started

πŸ’» All the resources you'll need to begin your Stellar project.
10
star
55

integration-tests

JavaScript
9
star
56

stellar-design-system

Components for Stellar’s design system
TypeScript
9
star
57

supercluster

Stellar-core integration test automation tool
F#
9
star
58

bower-js-stellar-sdk

JavaScript
9
star
59

soroban-rpc

RPC server for Soroban contracts.
Go
9
star
60

react-starter

Stellar's starter kit for React projects.
TypeScript
9
star
61

stellar-core-prometheus-exporter

Stellar Core Prometheus Exporter
Python
8
star
62

scp-proofs

SCP proofs and models
Python
8
star
63

product-conventions

A layout of all conventions to be used by all Stellar frontend products
JavaScript
8
star
64

soroban-react-payment

Soroban example dapps
TypeScript
7
star
65

django-polaris-circle

A reusable Django app for Circle USDC custody support in django-polaris deployments
Python
6
star
66

fca00c-asteroids

Learn Soroban and compete for a top spot on the leaderboard in Fast, Cheap & Out of Control
Rust
6
star
67

sorobounty-spectacular

Sorobounty Spectacular
5
star
68

sep24-reference-ui

TypeScript
5
star
69

regulated-assets-poc

JavaScript
5
star
70

core-node-admin-panel

TypeScript
5
star
71

recoverysigner-firebase-auth

A simple demo frontend web app for performing Firebase phone auth for use with recoverysigner.
TypeScript
5
star
72

soroflare

The Soroban environment and vm running on a Cloudflare Worker. (a simplified version of the backend running fca00c.com)
Rust
5
star
73

kotlin-wallet-sdk

Kotlin Wallet SDK to build Stellar wallets
Kotlin
5
star
74

sorobounties

The Soroban content bounty program
5
star
75

stellar-community-fund-contracts

Rust
4
star
76

stellar-turrets-docs

Docs repo for the Stellar Turrets protocol
4
star
77

anchor-transfer-utils

Utilities for anchors and wallets implementing SEP6 transfer protocol
TypeScript
4
star
78

stellar-upgrade-web

JavaScript
4
star
79

stellar-upgrade

Go
4
star
80

convert-stellar-address

JavaScript
4
star
81

soroban-name-service

Soroban name service
Rust
4
star
82

soroban-react-atomic-swap

A react demo dapp for making an atomic swap on Soroban
TypeScript
4
star
83

recoverysigner-demo-client

A limited feature demo client for a SEP-30 Recoverysigner server.
JavaScript
4
star
84

soroban-quest

Soroban Quest is a gamified educational course where you’ll learn Soroban and earn rewards!
Rust
4
star
85

solar-stellarorg

Stellar.org's Solar CSS framework theme
CSS
4
star
86

js-stellar-elements

Styled basic components for Stellar projects
JavaScript
3
star
87

solar-stellarorg-pages

CSS
3
star
88

golistcmp

A tool for comparing the output of 'go list -m -json all' executions.
Go
3
star
89

basic-payment-app

An example payments application demonstrating integrations of various features and SEPs in a user-facing product.
Svelte
3
star
90

soroban-dapps-challenge

Dapps for the Soroban Dapps Challenge
3
star
91

stellar-dbt-public

Public DBT instance to aid in data transformation for analytics purposes
Shell
3
star
92

bower-js-stellar-base

JavaScript
3
star
93

amm-reference-ui

A reference codebase to serve as a proof of concept for an AMM UI
TypeScript
3
star
94

helm-charts

Helm charts for deploying SDF maintained software
Smarty
3
star
95

stellar-account-prometheus-exporter

Stellar Account Prometheus Exporter - Monitor Stellar Network Accounts
Python
3
star
96

dts-xdr

A library for generating TypeScript declarations (.d.ts) for js-xdr auto-generated files.
JavaScript
3
star
97

crate-git-revision

Embed git revision into crates built and published.
Rust
2
star
98

actions

GitHub Actions for Stellar repositories.
TypeScript
2
star
99

project-viewer

Navigating projects on Stellar
Go
2
star
100

soroban-react-mint-token

An example dapp for minting tokens on Soroban
TypeScript
2
star