Prerequisites
- Node.js 20+ (required by the Stellar SDK)
- A Stellar testnet account (create at Stellar Laboratory)
- Freighter browser extension for wallet signing (browser only)
- Testnet XLM from the Stellar Testnet Faucet
Installation
| Package | Version | Purpose |
|---|---|---|
@stellar/stellar-sdk | ^14.x | Soroban contract calls, transaction building, XDR encoding |
@stellar/freighter-api | ^6.x | Browser wallet connection and signing |
Network Configuration
Contract Addresses
All addresses are available in Deployed Contracts. Import them centrally:Simulating (Reading) Contracts
For read-only operations, useserver.simulateTransaction(). No signing required.
Reading Pool State
Reading a User’s Margin Account
Connecting a Freighter Wallet
Executing Transactions
See Transaction Flow for the complete pattern: build → simulate → sign → submit.Reading Oracle Prices
Handling Errors
Soroban errors from contract panics appear in simulation asSimulationError or in transaction results as invokeHostFunctionError. Parse them:
InsufficientBalance— caller doesn’t have enough tokensInsufficientPoolBalance— pool can’t cover withdrawalRiskEngineNotInitialized— missing registry setup- Health factor check failure — logged as a contract panic with specific error code
Next Steps
Transaction Flow
Build, simulate, sign, and submit Soroban transactions step by step.
Mercury Indexer
Query historical events and transaction history via the Mercury indexer.
Integrate Lending
End-to-end guide for deposit and vToken redemption.
Integrate Margin
Create accounts, deposit collateral, and borrow assets.

