ts-xdbchain-sdk
v1.0.0
Published
A TypeScript SDK for interacting with XDBCHAIN - a Stellar-based blockchain network
Maintainers
Readme
XDBChain SDK - Exported Methods
Main Class: XDBChainSDK
Wallet Management
createWallet()- Create a new random walletloadWallet(secretKey: string)- Load an existing wallet from secret keycreateWalletFromSeed(seed: string | Buffer)- Create wallet from seedisValidAddress(address: string)- Validate a public addressisValidSecretKey(secretKey: string)- Validate a secret key
Keypair Management
generateKeypair()- Generate a new keypairkeypairFromSecret(secretKey: string)- Create keypair from secret keykeypairFromPublicKey(publicKey: string)- Create keypair from public key
Account Management
loadAccount(publicKey: string)- Load account informationcreateAccount(source: string, destination: string, startingBalance?: string)- Create new accountsetAccountOptions(secretKey: string, options: XDBAccountOptions)- Set account optionsmergeAccount(sourceSecret: string, destination: string)- Merge accountsbumpSequence(secretKey: string, bumpTo: string)- Bump sequence number
Balance Management
getBalances(publicKey: string)- Get all balancesgetXDBBalance(publicKey: string)- Get XDB balance onlywatchBalances(publicKey: string, callback)- Monitor balance changes in real-time
Payments
sendPayment(senderSecret: string, options: XDBPaymentOptions)- Send simple paymentsendPathPaymentStrictReceive(senderSecret: string, options: XDBPathPaymentOptions)- Path payment (fixed receive amount)sendPathPaymentStrictSend(senderSecret: string, options: XDBPathPaymentOptions)- Path payment (fixed send amount)sendBatchPayments(senderSecret: string, payments: XDBPaymentOptions[])- Multiple payments in batch
Trustline Management
addTrustline(walletSecret: string, options: XDBTrustlineOptions)- Add trustlineremoveTrustline(walletSecret: string, options)- Remove trustlinegetTrustlines(publicKey: string)- Get all trustlinesallowTrust(trustorSecret: string, trusteePublicKey: string, assetCode: string, authorize: boolean)- Authorize/revoke trust
Asset Management
createAssetObject(code: string, issuer?: string)- Create asset objectissueAsset(issuerSecret: string, distributorPublicKey: string, assetCode: string, amount: string, limit?: string)- Issue asset
Offer Management (DEX)
createSellOffer(secretKey: string, options: XDBOfferOptions)- Create sell offercreateBuyOffer(secretKey: string, options: XDBOfferOptions)- Create buy offercreatePassiveSellOffer(secretKey: string, options: XDBOfferOptions)- Create passive offercancelOffer(secretKey: string, offerId: string, selling: XDBAsset, buying: XDBAsset)- Cancel offergetOffers(publicKey: string, options?: XDBStreamOptions)- Get account offersgetOrderbook(selling: XDBAsset, buying: XDBAsset, limit?: number)- Get orderbook
Data Management
manageData(secretKey: string, options: XDBDataOptions)- Manage account data
Transaction and Operation Queries
getTransactionHistory(publicKey: string, options?: XDBStreamOptions)- Transaction historygetTransactionsForLedger(ledgerSequence: number, options?: XDBStreamOptions)- Transactions for ledgerwatchTransactions(publicKey: string, callback)- Monitor transactions in real-timegetOperations(publicKey: string, options?: XDBStreamOptions)- Get operationsgetOperationsForLedger(ledgerSequence: number, options?: XDBStreamOptions)- Operations for ledgergetOperationsForTransaction(transactionHash: string, options?: XDBStreamOptions)- Operations for transactiongetPayments(publicKey: string, options?: XDBStreamOptions)- Get paymentswatchPayments(publicKey: string, callback)- Monitor payments in real-time
Effects and Trade Queries
getEffects(publicKey: string, options?: XDBStreamOptions)- Get effectsgetEffectsForOperation(operationId: string, options?: XDBStreamOptions)- Effects for operationgetTrades(publicKey: string, options?: XDBStreamOptions)- Get tradesgetTradesForAssetPair(baseAsset: XDBAsset, counterAsset: XDBAsset, options?: XDBStreamOptions)- Trades for asset pair
Ledger Management
getLedger(sequence: number)- Get specific ledger informationgetLedgers(options?: XDBStreamOptions)- Get ledger list
Claimable Balance
createClaimableBalance(senderSecret: string, claimantPublicKey: string, amount: string, asset?: XDBAsset)- Create claimable balanceclaimBalance(claimantSecret: string, balanceId: string)- Claim balancegetClaimableBalances(publicKey: string)- Get claimable balances
Network and Fees
getNetworkInfo()- Network informationgetBaseFee()- Base feegetFeeStats()- Fee statisticsfundTestnetAccount(publicKey: string)- Fund testnet accountestimateFee(operationCount?: number)- Estimate fee
Path Finding
getPaymentPaths(sourcePublicKey: string, destination: XDBAsset, amount: string)- Find payment pathsgetStrictReceivePaths(sourceAccount: string, destination: XDBAsset, amount: string)- Strict receive pathsgetStrictSendPaths(sourceAsset: XDBAsset, destinationAssets: XDBAsset[], amount: string)- Strict send paths
Multi-Signature Transactions
signTransaction(transaction: Transaction, signers: Keypair[])- Sign transactioncreateMultiSigTransaction(sourceAccount: Account, operations: any[], signers: Keypair[])- Create multi-sig transaction
SDK Utilities
getServer()- Get Horizon server instancegetNetworkPassphrase()- Get network passphrasegetConfig()- Get SDK configurationsubmitTransaction(transaction: Transaction)- Submit transactionfromXDR(xdr: string)- Parse from XDR
Exported Utility Functions
createXDBChainSDK(config: XDBChainConfig)- SDK factorycreateMainnetSDK()- Mainnet SDKcreateFuturenetSDK()- Futurenet SDK (testnet)xdbToStroops(amount: number | string)- Convert XDB to stroopsstroopsToXdb(stroops: number | string)- Convert stroops to XDBisValidAmount(amount: string)- Validate amountformatAmount(amount: string, decimals?: number)- Format amountgenerateNonce()- Generate random nonceisValidMemo(memo: string, type?: string)- Validate memocalculateFee(operationCount: number, baseFee: number)- Calculate feeaccountExists(server: Horizon.Server, publicKey: string)- Check account existence
Exported TypeScript Interfaces
Configuration
XDBChainConfig- SDK configurationXDBWallet- Wallet representationXDBAsset- Asset representation
Operation Options
XDBPaymentOptions- Payment optionsXDBPathPaymentOptions- Path payment optionsXDBTrustlineOptions- Trustline optionsXDBAccountOptions- Account optionsXDBOfferOptions- Offer optionsXDBDataOptions- Data management optionsXDBStreamOptions- Streaming options
Response Data
XDBBalance- Account balanceXDBTransaction- TransactionXDBClaimableBalance- Claimable balanceXDBEffect- EffectXDBTrade- TradeXDBOrderbook- OrderbookXDBLedger- LedgerXDBOffer- OfferXDBPayment- Payment
Exported Error Classes
XDBChainError- Generic errorXDBNetworkError- Network errorXDBValidationError- Validation errorXDBTransactionError- Transaction errorXDBAssetError- Asset errorXDBOfferError- Offer error
Exported Constants
Account Flags
ACCOUNT_FLAGS- Account authorization flagsAUTH_REQUIRED_FLAG: 0x1AUTH_REVOCABLE_FLAG: 0x2AUTH_IMMUTABLE_FLAG: 0x4AUTH_CLAWBACK_ENABLED_FLAG: 0x8
Asset Types
ASSET_TYPE- Asset typesNATIVE: 'native'CREDIT_ALPHANUM4: 'credit_alphanum4'CREDIT_ALPHANUM12: 'credit_alphanum12'
Operation Types
OPERATION_TYPE- All supported operation typesCREATE_ACCOUNT,PAYMENT,PATH_PAYMENT_STRICT_RECEIVE, etc.
Default Configurations
Mainnet
- Horizon URL:
https://horizon.livenet.xdbchain.com/ - Network Passphrase:
LiveNet Global XDBChain Network ; November 2023
Futurenet (Testnet)
- Horizon URL:
https://horizon.futurenet.xdbchain.com/ - Network Passphrase:
Future XDBChain Network ; November 2023 - Friendbot:
https://friendbot.futurenet.xdbchain.com
Quick Usage Example
import { createMainnetSDK } from './xdbchain-sdk';
// Create SDK for mainnet
const sdk = createMainnetSDK();
// Create wallet
const wallet = await sdk.createWallet();
// Load account
const account = await sdk.loadAccount(wallet.publicKey);
// Send payment
await sdk.sendPayment(wallet.secretKey, {
destination: 'GDEST...',
amount: '10.5',
memo: 'Payment memo'
});