You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeScript SDK for the StellarSplit on-chain invoice splitting dApp on Stellar Soroban.
Install
npm install @stellar-split/sdk
Quick Start
import{StellarSplitClient,connectWallet,deadlineFromDays,parseAmount}from"@stellar-split/sdk";// Connect Freighter walletconstpublicKey=awaitconnectWallet();// Initialise clientconstclient=newStellarSplitClient({rpcUrl: "https://soroban-testnet.stellar.org",networkPassphrase: "Test SDF Network ; September 2015",contractId: "YOUR_CONTRACT_ID",});// Create an invoice splitting 100 USDC between two recipientsconst{ invoiceId, txHash }=awaitclient.createInvoice({creator: publicKey,recipients: [{address: "GABC...RECIPIENT1",amount: parseAmount("60")},{address: "GDEF...RECIPIENT2",amount: parseAmount("40")},],token: "USDC_CONTRACT_ADDRESS",deadline: deadlineFromDays(7),});console.log(`Invoice #${invoiceId} created: ${txHash}`);// Pay toward the invoiceawaitclient.pay({payer: publicKey,
invoiceId,amount: parseAmount("100"),});// Fetch invoice statusconstinvoice=awaitclient.getInvoice(invoiceId);console.log(invoice.status);// "Released"
Webhook Receiver
importexpressfrom'express';import{createWebhookMiddleware}from"@stellar-split/sdk";constapp=express();// Use raw body parser for webhook routeapp.use('/webhooks/stellarsplit',express.raw({type: 'application/json'}));// Secure webhook receiver with HMAC-SHA256 verification and replay protectionapp.post('/webhooks/stellarsplit',createWebhookMiddleware(process.env.WEBHOOK_SECRET!,{toleranceSeconds: 300,// 5 minutesnonceWindowSize: 1000,// Track 1000 recent nonces}),(req,res)=>{const{ event, data }=req.webhookPayload;switch(event){case'invoice.paid':
console.log('Payment received:',data);break;case'invoice.released':
console.log('Funds released:',data);break;}res.status(200).json({received: true});});