Skip to content

Repository files navigation

@stellar-sharpy/sdk

npmTypeScriptstellar-sdkLicenseVersion

TypeScript SDK for the Sharpy advanced split payment contract on Stellar Soroban. Wraps all contract interactions, wallet integration, and x402 agentic payment support into a clean, fully-typed API.

sharpy

Architecture

graph LR
App["sharpy-app\nNext.js 14"]
SDK["@stellar-sharpy/sdk"]
Freighter["Freighter Wallet"]
RPC["Soroban RPC\nstellar-sdk 16.0.1"]
Contract["Sharpy Contract\nProtocol 27"]
App -->|"createInvoice / pay"| SDK
Freighter -->|"signAuthEntry / signTransaction"| SDK
SDK -->|"simulate + submit"| RPC
RPC -->|"executes"| Contract
Loading

Install

npm install @stellar-sharpy/sdk

🎯 Live Testnet Transactions

See the SDK in action with real on-chain transactions:

Test Account: GD4Q2BH6...RS63


Quick Start

import{SharpyClient,connectWallet,deadlineFromDays,parseAmount,NETWORKS}from"@stellar-sharpy/sdk";// Connect Freighter walletconstpublicKey=awaitconnectWallet();// Initialize client — testnet pre-configuredconstclient=newSharpyClient(NETWORKS.testnet);// Create a split invoice — 60/40 between two recipientsconst{ invoiceId, txHash }=awaitclient.createInvoice({creator: publicKey,recipients: [{address: "GABC...RECIPIENT1",amount: parseAmount("600")},{address: "GDEF...RECIPIENT2",amount: parseAmount("400")},],token: "USDC_CONTRACT_ADDRESS",deadline: deadlineFromDays(7),});console.log(`Invoice #${invoiceId} created: ${txHash}`);// Pay the invoiceawaitclient.pay(publicKey,invoiceId,parseAmount("1000"));// Fetch statusconstinvoice=awaitclient.getInvoice(invoiceId);console.log(invoice.status);// "Released"

API Reference

SharpyClient

newSharpyClient(config: SharpyClientConfig)
FieldTypeDescription
rpcUrlstringSoroban RPC endpoint
networkPassphrasestringStellar network passphrase
contractIdstringDeployed contract ID

Invoice Methods

MethodReturnsDescription
createInvoice(params)Promise<{ invoiceId, txHash }>Create a new invoice with split rules and escrow options
createBatch(creator, invoices[])Promise<{ invoiceIds, txHash }>Create up to 10 invoices in one transaction
createRecurring(params)Promise<{ invoiceId, txHash }>Create recurring invoice with auto-generation on release
cancelInvoice(caller, invoiceId)Promise<{ txHash }>Creator cancels invoice and refunds all payments

Payment Methods

MethodReturnsDescription
pay(payer, invoiceId, amount)Promise<{ txHash }>Pay toward an invoice
poolPay(payer, payments[])Promise<{ txHash }>Pay multiple invoices in one call
releaseEscrow(caller, invoiceId)Promise<{ txHash }>Release escrow-held funds after delay
refund(caller, invoiceId)Promise<{ txHash }>Refund invoice after deadline

Escrow & Dispute Methods

MethodReturnsDescription
disputeRelease(caller, invoiceId)Promise<{ txHash }>Raise an escrow dispute
resolveDispute(caller, invoiceId, release)Promise<{ txHash }>Arbitrator resolves dispute

Read Methods

MethodReturnsDescription
getInvoice(id)Promise<Invoice>Fetch full invoice state by ID
getInvoiceStats(id)Promise<InvoiceStats>Fetch funded/total/completion_bps/unique_payers
getAuditLog(id)Promise<AuditEntry[]>Full on-chain audit trail
getPayerTotal(id, payer)Promise<bigint>Total amount paid by a specific address
getNextRecurring(id)Promise<number | null>Next invoice ID in recurring chain
getInvoiceFingerprint(id)Promise<string>SHA-256 content hash (Protocol 25/26)
previewPayout(id, amount)Promise<bigint[]>Preview exact per-recipient payouts with dust-correct rounding
getInvoicesByCreator(creator)Promise<number[]>Fetch all invoice IDs created by an address (on-chain index)
getClaimableBalance(account, token)Promise<bigint>Query internal credited balance after failed transfer

Fallback Recovery Methods

MethodReturnsDescription
claim(account, token)Promise<{ amount, txHash }>Withdraw credited balance after failed recipient transfer
getClaimableBalance(account, token)Promise<bigint>Query claimable balance for account/token

Protocol 25/26 Methods

MethodReturnsCAPDescription
bumpInvoiceTtl(caller, invoiceId)Promise<{ txHash }>CAP-78Extend invoice storage TTL to prevent archival
getInvoiceFingerprint(invoiceId)Promise<string>CAP-75/82SHA-256 tamper-evident content hash
previewPayout(invoiceId, amount)Promise<bigint[]>CAP-82Preview split distribution with checked arithmetic

Wallet Helpers

FunctionReturnsDescription
connectWallet()Promise<string>Connect Freighter, return public key
getWalletPublicKey()Promise<string | null>Get currently connected public key
signTransaction(xdr, passphrase)Promise<string>Sign a transaction XDR

Utilities

FunctionDescription
parseAmount(value)Parse USDC string to stroops (bigint) — "10.5"105_000_000n
formatAmount(stroops)Format stroops as USDC string — 105_000_000n"10.5"
deadlineFromDays(days)Unix timestamp N days from now
isExpired(deadline)Check if a deadline has passed
isValidAddress(address)Validate a Stellar G... address
truncateAddress(address)Truncate for display: GABC...XYZ
explorerUrl(network, id, type)Build Stellar Expert explorer URL

NETWORKS Constant

import{NETWORKS}from"@stellar-sharpy/sdk";// Testnet — pre-configured with deployed contract IDconstclient=newSharpyClient(NETWORKS.testnet);// { rpcUrl, networkPassphrase, contractId }// Mainnetconstclient=newSharpyClient(NETWORKS.mainnet);

Error Handling

The SDK exports typed error classes for graceful handling:

import{InvoiceNotFoundError,DeadlinePassedError,InvoiceNotPendingError,OverpaymentError,}from"@stellar-sharpy/sdk";try{awaitclient.pay(publicKey,invoiceId,parseAmount("100"));}catch(e){if(einstanceofDeadlinePassedError){console.error("Invoice deadline has passed");}elseif(einstanceofOverpaymentError){console.error("Payment exceeds remaining balance");}}

Types

interfaceInvoice{version: number;creator: string;recipients: string[];amounts: bigint[];tokens: string[];deadline: number;funded: bigint;status: "Pending"|"Released"|"Refunded"|"Cancelled";escrowEnabled: boolean;escrowReleaseDelay: number;completionTime?: number;}typeSplitRule=|{type: "Fixed";amount: bigint}|{type: "Percentage";bps: number}|{type: "Tiered";threshold: bigint;bps: number};interfaceAuditEntry{action: string;actor: string;timestamp: number;}

Build & Development

npm run build # tsup — ESM + CJS + TypeScript declarations
npm run dev # watch mode
npm run lint # tsc --noEmit
npm test# vitest

Protocol Compatibility

stellar-sdkProtocolStatus
16.0.127✅ Current

Related Repos

RepoDescription
sharpy-contractsSoroban smart contract (Rust)
sharpy-appNext.js 14 frontend dApp

Contributing

See CONTRIBUTING.md for setup, standards, and commit conventions.

Security

See SECURITY.md for the vulnerability disclosure process.

License

MIT

About

TypeScript SDK for the Sharpy split payment protocol on Stellar Soroban

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages