This document describes the server-side integration with the Soroban remittance_split contract.
Add to your .env.local:
STELLAR_NETWORK=testnet
REMITTANCE_SPLIT_CONTRACT_ID=<your_deployed_contract_id>Prerequisites:
- The remittance_split contract must be deployed on the specified network
- The contract ID must be set in environment variables
Located in lib/contracts/remittance-split.ts:
Reads the current split configuration from the contract.
const config = await getSplit('testnet');
// Returns: { savings_percent, bills_percent, insurance_percent, family_percent } | nullAlias for getSplit().
Calculates split amounts based on the configured percentages.
const amounts = await calculateSplit(1000, 'testnet');
// Returns: { savings, bills, insurance, family, remainder } | nullReturns the current split configuration percentages.
Response:
{
"percentages": {
"savings": 30,
"bills": 25,
"insurance": 10,
"family": 20
}
}Calculates split amounts for a given remittance amount.
Query Parameters:
amount(required): The total amount to split
Response:
{
"amounts": {
"savings": "300",
"bills": "250",
"insurance": "100",
"family": "200",
"remainder": "150"
}
}All endpoints handle the following errors:
- Contract not configured: Returns 500 with message "REMITTANCE_SPLIT_CONTRACT_ID not configured"
- Contract not deployed: Returns 404 with message "Split configuration not found"
- RPC errors: Returns 500 with descriptive error message
- Invalid parameters: Returns 400 with validation error
// Fetch current configuration
const response = await fetch('/api/split');
const { percentages } = await response.json();
// Calculate split for amount
const response = await fetch('/api/split/calculate?amount=1000');
const { amounts } = await response.json();