Welcome to StellarKit API! This guide will help you set up the project, understand the basics, and make your first API calls. If you encounter unfamiliar Stellar terminology, check the Glossary.
Before you begin, make sure you have the following installed:
- Node.js >= 18 (see nodejs.org)
- npm >= 9 (comes with Node.js)
- A text editor or IDE (VS Code, Sublime Text, WebStorm, etc.)
- Git (optional, for cloning the repository)
git clone https://github.com/stellarkit-lab-devtools/stellarkit-api.git
cd stellarkit-apiOr, if you don't have Git, download the repository as a ZIP and extract it.
npm installThis installs all required packages, including Express, the Stellar SDK, and testing tools.
Copy the example environment file:
cp .env.example .envOpen .env in your text editor and review the settings:
STELLAR_NETWORK=testnet
PORT=3000
NODE_ENV=development
RATE_LIMIT_MAX=100
CACHE_TTL_MS=5000Key settings:
STELLAR_NETWORK: Usetestnetfor development (free, resets periodically). Usemainnetfor production.PORT: The port where the API will listen. Default is3000.NODE_ENV: Set todevelopmentfor detailed logs. Useproductionfor a live server.
For now, keep the defaults and save the file.
npm run devThe API will start with auto-reload enabled. When you edit files, the server automatically restarts.
Output:
Server running on http://localhost:3000
Network: testnet
npm startThe server starts without file watching, suitable for deployment.
Open your browser and visit:
http://localhost:3000
You'll see a list of all available endpoints.
Test the health endpoint:
curl http://localhost:3000/healthExpected response:
{
"success": true,
"data": {
"status": "ok",
"service": "StellarKit API",
"version": "1.0.0",
"network": "testnet"
}
}- Create a new GET request to
http://localhost:3000/health - Send the request
- You'll see the same JSON response as above
Before making more advanced calls, understand these core Stellar ideas:
A Stellar account is a public/private key pair. The public key (starting with G) is your address; the private key is your secret. Every account must hold at least 1 XLM to exist on the network.
A transaction is a signed request to the network (e.g., send XLM, create a trustline, trade assets). Transactions are bundled into a ledger every ~5 seconds.
Stellar measures fees and reserves in stroops, the smallest unit of XLM. 1 XLM = 10,000,000 stroops. APIs often report values in stroops because they're exact integers.
For more terms, see the Glossary.
Fetch details for any Stellar account:
curl "http://localhost:3000/account/GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN"Response includes:
- XLM balance
- Asset balances (if any)
- Sequence number
- Signers and thresholds
- Minimum reserve requirement
- Spendable balance
See current fee estimates and ledger info:
curl http://localhost:3000/network-statusResponse includes:
- Latest ledger sequence
- Base fee in stroops and XLM
- Protocol version
- Transaction count
Calculate how much a transaction will cost:
curl "http://localhost:3000/fee-estimate?operationCount=3"Response includes economy, standard, and priority fee tiers.
Retrieve recent transactions for an account:
curl "http://localhost:3000/transactions/GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN"Find all issuers of a given asset code:
curl "http://localhost:3000/asset/search?code=USDC"Use Friendbot (Stellar's testnet faucet) to create and fund a new account:
npm run seedThis script generates a keypair and funds it with 10,000 XLM on testnet. Save the public key—you'll use it in API calls.
If you already have a testnet public key, you can query it directly:
curl "http://localhost:3000/account/YOUR_PUBLIC_KEY"Replace YOUR_PUBLIC_KEY with an actual Stellar testnet account (starting with G).
StellarKit API includes comprehensive tests. Run them with:
npm testTests validate all endpoints, error handling, and edge cases. If you modify the code, run tests to ensure nothing breaks.
async function getAccount(accountId) {
const response = await fetch(`http://localhost:3000/account/${accountId}`);
const payload = await response.json();
if (!response.ok) {
console.error("Error:", payload.error.message);
return null;
}
return payload.data;
}
// Usage
const account = await getAccount("GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN");
console.log("XLM Balance:", account.xlm.balance);import type { AccountResponse } from "stellarkit-api";
async function getAccount(accountId: string): Promise<AccountResponse | null> {
const response = await fetch(`http://localhost:3000/account/${accountId}`);
const payload = await response.json();
if (!response.ok) {
console.error("Error:", payload.error.message);
return null;
}
return payload.data as AccountResponse;
}Every response from StellarKit API follows a standard envelope:
{
"success": true,
"data": { /* endpoint-specific data */ },
"meta": { /* optional pagination or metadata */ }
}{
"success": false,
"error": {
"type": "ACCOUNT_NOT_FOUND",
"message": "Account does not exist on the Stellar network"
}
}Always check success to know whether to process data or error.
If you get "Error: listen EADDRINUSE", the default port 3000 is already in use. Change it:
PORT=3001 npm run devThen access the API at http://localhost:3001.
If you see "Error: Unable to connect to Horizon," check:
- Your internet connection
- The value of
STELLAR_NETWORKin.env(should betestnetormainnet) - Try restarting the server
Stellar account IDs must:
- Start with
G - Be exactly 56 characters long
- Contain only alphanumeric characters
If you see "Invalid Stellar account ID," double-check the key you're using.
- Explore the API: Visit
http://localhost:3000to browse all endpoints. - Read the README: Check README.md for full endpoint documentation.
- Review the Glossary: See Glossary for Stellar terminology.
- Check Examples: Look in the
examples/folder for real-world scripts. - Contribute: See CONTRIBUTING.md for how to contribute.
- Documentation: developers.stellar.org
- Community: Stellar Developers Slack
- GitHub Issues: stellarkit-lab-devtools/stellarkit-api
Happy building! 🚀