Reusable TypeScript helper package for the Stellar PocketPay mobile app and other Stellar Testnet applications.
| Module | Functions |
|---|---|
| Wallet | createWallet, importWallet, getPublicKey, getBalance, fundTestnetAccount |
| Payments | sendXLM |
| Transactions | getTransactions, getPayments |
| Soroban | depositToVault, withdrawFromVault, getVaultBalance |
| Config | resolveConfig, getHorizonServer, getNetworkPassphrase |
| Utils | validatePublicKey, validateSecretKey, validateAmount, stroopsToXLM, xlmToStroops, truncateAddress |
npm install stellar-pocketpay-sdkOr clone and link locally:
git clone https://github.com/Stellar-PocketPay/stellar-pocketpay-sdk.git
cd stellar-pocketpay-sdk
npm install
npm run build
npm linkimport {
createWallet,
fundTestnetAccount,
getBalance,
sendXLM,
} from 'stellar-pocketpay-sdk';
// 1. Create a wallet
const wallet = createWallet();
console.log('Public Key:', wallet.publicKey);
// 2. Fund on testnet
await fundTestnetAccount(wallet.publicKey);
// 3. Check balance
const balance = await getBalance(wallet.publicKey);
console.log('XLM:', balance.nativeBalance);
// 4. Send XLM
const result = await sendXLM({
sourceSecret: wallet.secretKey,
destination: 'GDEST...',
amount: '10',
memo: 'coffee',
});
console.log('TX Hash:', result.hash);stellar-pocketpay-sdk/
├── src/
│ ├── config/ # Network configuration & server factories
│ ├── wallet/ # Keypair management, balances, funding
│ ├── payments/ # XLM payment transactions
│ ├── transactions/ # Transaction & payment history queries
│ ├── soroban/ # Savings vault contract interactions
│ ├── types/ # All TypeScript type definitions
│ ├── utils/ # Validation, formatting, error helpers
│ └── index.ts # Barrel export
├── tests/ # Vitest test suites
├── examples/ # Runnable example scripts
├── .env.example # Environment variable template
├── tsconfig.json # TypeScript configuration
├── vitest.config.ts # Test configuration
└── package.json
The SDK defaults to Stellar Testnet. Configure via environment variables or programmatic overrides:
# .env
STELLAR_NETWORK=testnet
STELLAR_HORIZON_URL=https://horizon-testnet.stellar.org
STELLAR_SOROBAN_RPC_URL=https://soroban-testnet.stellar.org
VAULT_CONTRACT_ID=CXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXOr pass config directly:
import { getBalance } from 'stellar-pocketpay-sdk';
const balance = await getBalance('GABCD...', {
network: 'testnet',
horizonUrl: 'https://custom-horizon.example.com',
});Creates a new random Stellar keypair. Does not activate it on-chain.
Imports an existing wallet from a secret key.
Derives the public key from a secret key.
Fetches all asset balances for an account. Returns a nativeBalance shortcut for XLM.
Funds an account with 10,000 XLM via Friendbot. Testnet only.
Sends XLM from one account to another. Supports optional memo text (max 28 bytes).
interface SendXLMParams {
sourceSecret: string;
destination: string;
amount: string;
memo?: string;
}Fetches recent transactions for an account.
Fetches recent payment operations for an account.
Deposits XLM into the savings vault smart contract.
Withdraws XLM from the savings vault smart contract.
Queries the vault balance for a user.
Run examples directly with tsx:
# Create a wallet, fund it, check balance
npx tsx examples/create-wallet.ts
# Send XLM between two accounts
npx tsx examples/send-xlm.ts
# Vault operations (requires deployed contract)
VAULT_CONTRACT_ID=CXXXXX npx tsx examples/vault-operations.ts# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Type-check without emitting
npm run lintAll SDK functions throw PocketPayError with structured error information:
import { getBalance, PocketPayError } from 'stellar-pocketpay-sdk';
try {
const balance = await getBalance('GINVALID...');
} catch (error) {
if (error instanceof PocketPayError) {
console.error(error.code); // "INVALID_PUBLIC_KEY"
console.error(error.message); // Human-readable message
console.error(error.statusCode); // HTTP status (if applicable)
}
}| Code | Description |
|---|---|
INVALID_PUBLIC_KEY |
Invalid Stellar public key format |
INVALID_SECRET_KEY |
Invalid Stellar secret key format |
INVALID_AMOUNT |
Non-positive or non-numeric amount |
INVALID_AMOUNT_PRECISION |
More than 7 decimal places |
INVALID_MEMO |
Memo exceeds 28-byte limit |
SELF_PAYMENT |
Source and destination are the same |
ACCOUNT_NOT_FOUND |
Account doesn't exist on network |
TESTNET_ONLY |
Operation only available on testnet |
PAYMENT_FAILED |
Transaction rejected by network |
MISSING_CONTRACT_ID |
Vault contract ID not provided |
⚠️ Never hardcode secret keys. Always use environment variables or function parameters.
- Secret keys should be stored securely (e.g., encrypted storage, OS keychain)
- The
.envfile is gitignored — use.env.exampleas a template - All examples use dynamically generated keys
MIT © Stellar PocketPay