js-stellar-sdk
Stellar JS SDK
Build applications on the Stellar network using @stellar/stellar-sdk (v14.x, Node 20+).
Installation
npm install @stellar/stellar-sdk
Import only what you need:
import {
Keypair,
Horizon,
rpc,
TransactionBuilder,
Networks,
Operation,
Asset,
Memo,
BASE_FEE,
} from "@stellar/stellar-sdk";
Never install @stellar/stellar-base separately — the SDK re-exports everything from it.
Quick Start
import {
Keypair,
Horizon,
TransactionBuilder,
Networks,
Operation,
Asset,
BASE_FEE,
} from "@stellar/stellar-sdk";
// 1. Create keypair and fund on testnet
const keypair = Keypair.random();
await fetch(`https://friendbot.stellar.org?addr=${keypair.publicKey()}`);
// 2. Connect to Horizon
const server = new Horizon.Server("https://horizon-testnet.stellar.org");
// 3. Build, sign, submit a payment
const account = await server.loadAccount(keypair.publicKey());
const tx = new TransactionBuilder(account, {
fee: BASE_FEE,
networkPassphrase: Networks.TESTNET,
})
.addOperation(
Operation.payment({
destination: "GABC...",
asset: Asset.native(),
amount: "10",
}),
)
.setTimeout(30)
.build();
tx.sign(keypair);
const result = await server.submitTransaction(tx);
Core Workflow
Every Stellar JS SDK interaction follows this pattern:
- Connect — create
Horizon.Serverorrpc.Serverinstance - Load account — fetch current sequence number via
server.loadAccount() - Build transaction — use
TransactionBuilderwith operations - Sign — call
transaction.sign(keypair) - Submit — call
server.submitTransaction(transaction)
Always set .setTimeout(30) on transactions. Always handle errors by inspecting error.response.data.extras.result_codes.
Key Concepts
- Stroops: 1 XLM = 10,000,000 stroops.
BASE_FEE= 100 stroops. - Amounts: Always strings with up to 7 decimal places (e.g.,
'100.1234567'). - Sequence numbers: Auto-managed when using
server.loadAccount(). - Network passphrase: Transactions are network-specific. Use
Networks.TESTNET,Networks.PUBLIC, etc. - Trustlines: Required before receiving any non-XLM asset.
- Base reserve: 0.5 XLM per account subentry (trustlines, offers, signers, data entries).
- Max 100 operations per transaction (1 for smart contract operations).
When to Use Horizon vs RPC
| Use Case | Module |
|---|---|
| Account balances, payment history, transaction queries | Horizon.Server |
| Streaming payments, transactions, effects | Horizon.Server (.stream()) |
| Orderbook, DEX trading, trade history | Horizon.Server |
| Asset info, fee stats, ledger data | Horizon.Server |
| Smart contract interactions | rpc.Server |
Transaction simulation (simulateTransaction) |
rpc.Server |
| Contract events | rpc.Server |
Preparing contract transactions (prepareTransaction) |
rpc.Server |
Reference Files
-
API Reference: Complete class/method reference for all SDK modules — Keypair, TransactionBuilder, Horizon.Server, rpc.Server, Operations, Assets, contract module, WebAuth, Federation, StellarToml, XDR helpers. Read when you need specific method signatures or parameter details.
-
Code Examples: Working code examples for all common tasks — payments, path payments, asset issuance, trustlines, DEX trading, streaming, fee-bumps, claimable balances, sponsored reserves, multisig, RPC interactions, SEP-10 auth, federation, error handling. Read when implementing a specific feature.
-
Networks & Configuration: Network URLs, passphrases, Friendbot, testnet/mainnet switching, CLI bindings generation, browser/React Native setup, key limits. Read when configuring the SDK for a specific environment or deploying to a different network.
More from padparadscho/skills
rs-ratatui-crate
Build terminal user interfaces (TUIs) in Rust with Ratatui (v0.30). Use this skill whenever working with the ratatui crate for creating interactive terminal applications, including: (1) Setting up a new Ratatui project, (2) Creating or modifying terminal UI layouts, (3) Implementing widgets (lists, tables, charts, text, gauges, etc.), (4) Handling keyboard/mouse input and events, (5) Structuring TUI application architecture (TEA, component-based, or monolithic patterns), (6) Writing custom widgets, (7) Managing application state in a TUI context, (8) Terminal setup/teardown and panic handling, (9) Testing TUI rendering with TestBackend. Also triggers for questions about crossterm event handling in a Ratatui context, tui-input, tui-textarea, or any ratatui-* ecosystem crate.
22js-gnome-extensions
Build, debug, and maintain GNOME Shell extensions using GJS (GNOME JavaScript). Covers extension anatomy (metadata.json, extension.js, prefs.js, stylesheet.css), ESModule imports, GSettings preferences, popup menus, quick settings, panel indicators, dialogs, notifications, search providers, translations, and session modes. Use when the user wants to: (1) Create a new GNOME Shell extension, (2) Add UI elements like panel buttons, popup menus, quick settings toggles/sliders, or modal dialogs, (3) Implement extension preferences with GTK4/Adwaita, (4) Debug or test an extension, (5) Port an extension to a newer GNOME Shell version (45-49+), (6) Prepare an extension for submission to extensions.gnome.org, (7) Work with GNOME Shell internal APIs (Clutter, St, Meta, Shell, Main).
7js-gnome-apps
Build native GNOME desktop applications using JavaScript (GJS) with GTK 4, Libadwaita, and the GNOME platform. Use when the user wants to create, modify, or debug a GNOME app written in JavaScript/GJS, including UI design with XML or Blueprint, GObject subclassing, Meson build setup, Flatpak packaging, or any task involving GJS bindings for GLib/GIO/GTK4/Adw libraries. Also use when working with `.ui` files, `meson.build`, GResource XML, GSettings schemas, `.desktop` files, or Flatpak manifests in a GJS project context.
6rs-soroban-sdk
Expert guidance for building smart contracts on Stellar using the Soroban Rust SDK. Use this skill when working with Soroban smart contracts for tasks including (1) creating new contracts with [contract] and [contractimpl] attributes, (2) implementing storage with Persistent, Temporary, or Instance storage types, (3) working with auth contexts and authorization, (4) handling tokens and Stellar Asset Contracts, (5) writing tests with testutils, (6) deploying contracts, (7) working with events and logging, (8) using crypto functions, (9) debugging contract errors, (10) security best practices and vulnerability prevention, (11) avoiding common security pitfalls like missing authorization, integer overflow, or reinitialization attacks.
5js-stronghold-sdk
Guide for integrating and building with the Stronghold Pay JS SDK and REST API for payment processing. Use when working with Stronghold Pay payment integration, accepting ACH/bank debit payments, linking bank accounts, creating charges/tips, generating PayLinks, or building checkout flows — in sandbox or live environments. Covers Stronghold.Pay.JS drop-in UI, REST API v2 endpoints, PayLink hosted payment pages, customer token management, and payment source handling.
3rs-yew-crate
Expert guidance for building Rust + WebAssembly frontend web applications using the Yew framework (v0.22). Use when creating, modifying, debugging, or architecting Yew applications — including function components, hooks, props, routing, contexts, events, server-side rendering, agents, and Suspense. Covers project setup with Trunk, the html! macro, state management, data fetching, and integration with the broader Yew/WASM ecosystem (yew-router, gloo, wasm-bindgen, web-sys, stylist, yewdux).
2