Introduction
⏱️ 2 min read
Last updated
import StellarSdk from 'stellar-sdk';
class ApiClient {
private readonly apiUrl = "api.defindex.io";
private readonly apiKey: string;
constructor(apiKey: string) {
this.apiKey = apiKey;
}
// Helper for POST requests
async postData(endpoint: string, vaultAddress: string, params: Record<string, any>): Promise<any> {
const response = await fetch(`https://${this.apiUrl}/vault/${vaultAddress}/${endpoint}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${this.apiKey}`
},
body: JSON.stringify(params)
});
return await response.json();
}
// Helper for GET requests
async getData(endpoint: string, vaultAddress: string, params?: Record<string, any>): Promise<any> {
const url = params
? `https://${this.apiUrl}/vault/${vaultAddress}/${endpoint}?${new URLSearchParams(params).toString()}`
: `https://${this.apiUrl}/vault/${vaultAddress}/${endpoint}`;
const response = await fetch(url, {
method: 'GET',
headers: {
'Authorization': `Bearer ${this.apiKey}`
}
});
return await response.json();
}
}{
amounts: [10000000], // Array of amounts for each vault asset (7 decimals for XLM)
caller: userAddress, // User's wallet address
}{
amounts: [5000000], // Array of amounts to withdraw from each asset
caller: userAddress, // User's wallet address
}{
xdr: signedXdr // Signed transaction XDR
}