UNPKG

ts-xdbchain-sdk

Version:

A TypeScript SDK for interacting with XDBCHAIN - a Stellar-based blockchain network

204 lines (165 loc) 8.76 kB
# XDBChain SDK - Exported Methods ## Main Class: XDBChainSDK ### Wallet Management - `createWallet()` - Create a new random wallet - `loadWallet(secretKey: string)` - Load an existing wallet from secret key - `createWalletFromSeed(seed: string | Buffer)` - Create wallet from seed - `isValidAddress(address: string)` - Validate a public address - `isValidSecretKey(secretKey: string)` - Validate a secret key ### Keypair Management - `generateKeypair()` - Generate a new keypair - `keypairFromSecret(secretKey: string)` - Create keypair from secret key - `keypairFromPublicKey(publicKey: string)` - Create keypair from public key ### Account Management - `loadAccount(publicKey: string)` - Load account information - `createAccount(source: string, destination: string, startingBalance?: string)` - Create new account - `setAccountOptions(secretKey: string, options: XDBAccountOptions)` - Set account options - `mergeAccount(sourceSecret: string, destination: string)` - Merge accounts - `bumpSequence(secretKey: string, bumpTo: string)` - Bump sequence number ### Balance Management - `getBalances(publicKey: string)` - Get all balances - `getXDBBalance(publicKey: string)` - Get XDB balance only - `watchBalances(publicKey: string, callback)` - Monitor balance changes in real-time ### Payments - `sendPayment(senderSecret: string, options: XDBPaymentOptions)` - Send simple payment - `sendPathPaymentStrictReceive(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 trustline - `removeTrustline(walletSecret: string, options)` - Remove trustline - `getTrustlines(publicKey: string)` - Get all trustlines - `allowTrust(trustorSecret: string, trusteePublicKey: string, assetCode: string, authorize: boolean)` - Authorize/revoke trust ### Asset Management - `createAssetObject(code: string, issuer?: string)` - Create asset object - `issueAsset(issuerSecret: string, distributorPublicKey: string, assetCode: string, amount: string, limit?: string)` - Issue asset ### Offer Management (DEX) - `createSellOffer(secretKey: string, options: XDBOfferOptions)` - Create sell offer - `createBuyOffer(secretKey: string, options: XDBOfferOptions)` - Create buy offer - `createPassiveSellOffer(secretKey: string, options: XDBOfferOptions)` - Create passive offer - `cancelOffer(secretKey: string, offerId: string, selling: XDBAsset, buying: XDBAsset)` - Cancel offer - `getOffers(publicKey: string, options?: XDBStreamOptions)` - Get account offers - `getOrderbook(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 history - `getTransactionsForLedger(ledgerSequence: number, options?: XDBStreamOptions)` - Transactions for ledger - `watchTransactions(publicKey: string, callback)` - Monitor transactions in real-time - `getOperations(publicKey: string, options?: XDBStreamOptions)` - Get operations - `getOperationsForLedger(ledgerSequence: number, options?: XDBStreamOptions)` - Operations for ledger - `getOperationsForTransaction(transactionHash: string, options?: XDBStreamOptions)` - Operations for transaction - `getPayments(publicKey: string, options?: XDBStreamOptions)` - Get payments - `watchPayments(publicKey: string, callback)` - Monitor payments in real-time ### Effects and Trade Queries - `getEffects(publicKey: string, options?: XDBStreamOptions)` - Get effects - `getEffectsForOperation(operationId: string, options?: XDBStreamOptions)` - Effects for operation - `getTrades(publicKey: string, options?: XDBStreamOptions)` - Get trades - `getTradesForAssetPair(baseAsset: XDBAsset, counterAsset: XDBAsset, options?: XDBStreamOptions)` - Trades for asset pair ### Ledger Management - `getLedger(sequence: number)` - Get specific ledger information - `getLedgers(options?: XDBStreamOptions)` - Get ledger list ### Claimable Balance - `createClaimableBalance(senderSecret: string, claimantPublicKey: string, amount: string, asset?: XDBAsset)` - Create claimable balance - `claimBalance(claimantSecret: string, balanceId: string)` - Claim balance - `getClaimableBalances(publicKey: string)` - Get claimable balances ### Network and Fees - `getNetworkInfo()` - Network information - `getBaseFee()` - Base fee - `getFeeStats()` - Fee statistics - `fundTestnetAccount(publicKey: string)` - Fund testnet account - `estimateFee(operationCount?: number)` - Estimate fee ### Path Finding - `getPaymentPaths(sourcePublicKey: string, destination: XDBAsset, amount: string)` - Find payment paths - `getStrictReceivePaths(sourceAccount: string, destination: XDBAsset, amount: string)` - Strict receive paths - `getStrictSendPaths(sourceAsset: XDBAsset, destinationAssets: XDBAsset[], amount: string)` - Strict send paths ### Multi-Signature Transactions - `signTransaction(transaction: Transaction, signers: Keypair[])` - Sign transaction - `createMultiSigTransaction(sourceAccount: Account, operations: any[], signers: Keypair[])` - Create multi-sig transaction ### SDK Utilities - `getServer()` - Get Horizon server instance - `getNetworkPassphrase()` - Get network passphrase - `getConfig()` - Get SDK configuration - `submitTransaction(transaction: Transaction)` - Submit transaction - `fromXDR(xdr: string)` - Parse from XDR ## Exported Utility Functions - `createXDBChainSDK(config: XDBChainConfig)` - SDK factory - `createMainnetSDK()` - Mainnet SDK - `createFuturenetSDK()` - Futurenet SDK (testnet) - `xdbToStroops(amount: number | string)` - Convert XDB to stroops - `stroopsToXdb(stroops: number | string)` - Convert stroops to XDB - `isValidAmount(amount: string)` - Validate amount - `formatAmount(amount: string, decimals?: number)` - Format amount - `generateNonce()` - Generate random nonce - `isValidMemo(memo: string, type?: string)` - Validate memo - `calculateFee(operationCount: number, baseFee: number)` - Calculate fee - `accountExists(server: Horizon.Server, publicKey: string)` - Check account existence ## Exported TypeScript Interfaces ### Configuration - `XDBChainConfig` - SDK configuration - `XDBWallet` - Wallet representation - `XDBAsset` - Asset representation ### Operation Options - `XDBPaymentOptions` - Payment options - `XDBPathPaymentOptions` - Path payment options - `XDBTrustlineOptions` - Trustline options - `XDBAccountOptions` - Account options - `XDBOfferOptions` - Offer options - `XDBDataOptions` - Data management options - `XDBStreamOptions` - Streaming options ### Response Data - `XDBBalance` - Account balance - `XDBTransaction` - Transaction - `XDBClaimableBalance` - Claimable balance - `XDBEffect` - Effect - `XDBTrade` - Trade - `XDBOrderbook` - Orderbook - `XDBLedger` - Ledger - `XDBOffer` - Offer - `XDBPayment` - Payment ## Exported Error Classes - `XDBChainError` - Generic error - `XDBNetworkError` - Network error - `XDBValidationError` - Validation error - `XDBTransactionError` - Transaction error - `XDBAssetError` - Asset error - `XDBOfferError` - Offer error ## Exported Constants ### Account Flags - `ACCOUNT_FLAGS` - Account authorization flags - `AUTH_REQUIRED_FLAG: 0x1` - `AUTH_REVOCABLE_FLAG: 0x2` - `AUTH_IMMUTABLE_FLAG: 0x4` - `AUTH_CLAWBACK_ENABLED_FLAG: 0x8` ### Asset Types - `ASSET_TYPE` - Asset types - `NATIVE: 'native'` - `CREDIT_ALPHANUM4: 'credit_alphanum4'` - `CREDIT_ALPHANUM12: 'credit_alphanum12'` ### Operation Types - `OPERATION_TYPE` - All supported operation types - `CREATE_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 ```typescript 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' }); ```