πBackend API
The BackendApiService provides a comprehensive interface to interact with the Sodax Backend API, offering access to Intent, Solver, and Money Market data. This service is automatically initialized when creating a Sodax instance and can be accessed through the backendApiService property.
Table of Contents
Initialization
The BackendApiService is automatically initialized when creating a Sodax instance. You can configure it by passing a backendApiConfig in the Sodax constructor.
Basic Initialization
import { Sodax } from '@sodax/sdk';
// Initialize with default configuration
const sodax = new Sodax();
const backendApi = sodax.backendApi;Custom Configuration
Configuration
BackendApiConfig Type
Default Configuration
Intent Endpoints
Get Intent by Transaction Hash
Retrieves intent details using a transaction hash.
Request:
Method: GET
Endpoint:
/intent/tx/{txHash}Parameters:
txHash(string) - The transaction hash
Response:
Example Response:
Get Intent by Intent Hash
Retrieves intent details using an intent hash.
Request:
Method: GET
Endpoint:
/intent/{intentHash}Parameters:
intentHash(string) - The intent hash
Response: Same as getIntentByTxHash
Solver Endpoints
Get Orderbook
Retrieves the solver orderbook with pagination support.
Request:
Method: GET
Endpoint:
/solver/orderbook?offset={offset}&limit={limit}Parameters:
offset(string) - Starting position for paginationlimit(string) - Maximum number of items to return
Response:
Example Response:
Money Market Endpoints
Get User Position
Retrieves money market position for a specific user.
Request:
Method: GET
Endpoint:
/moneymarket/position/{userAddress}Parameters:
userAddress(string) - User's wallet address
Response:
Example Response:
Get All Money Market Assets
Retrieves all available money market assets.
Request:
Method: GET
Endpoint:
/moneymarket/asset/all
Response:
Example Response:
Get Specific Money Market Asset
Retrieves details for a specific money market asset.
Request:
Method: GET
Endpoint:
/moneymarket/asset/{reserveAddress}Parameters:
reserveAddress(string) - Reserve contract address
Response: Same as MoneyMarketAsset interface
Get Asset Borrowers
Retrieves borrowers for a specific money market asset with pagination.
Request:
Method: GET
Endpoint:
/moneymarket/asset/{reserveAddress}/borrowers?offset={offset}&limit={limit}Parameters:
reserveAddress(string) - Reserve contract addressoffset(string) - Starting position for paginationlimit(string) - Maximum number of items to return
Response:
Example Response:
Get Asset Suppliers
Retrieves suppliers for a specific money market asset with pagination.
Request:
Method: GET
Endpoint:
/moneymarket/asset/{reserveAddress}/suppliers?offset={offset}&limit={limit}Parameters:
reserveAddress(string) - Reserve contract addressoffset(string) - Starting position for paginationlimit(string) - Maximum number of items to return
Response:
Example Response:
Get All Money Market Borrowers
Retrieves all money market borrowers with pagination.
Request:
Method: GET
Endpoint:
/moneymarket/borrowers?offset={offset}&limit={limit}Parameters:
offset(string) - Starting position for paginationlimit(string) - Maximum number of items to return
Response:
Error Handling
The BackendApiService includes comprehensive error handling for various scenarios:
Timeout Errors
HTTP Errors
Network Errors
Utility Methods
Set Custom Headers
You can dynamically set custom headers for API requests:
Get Base URL
Retrieve the current base URL being used:
Complete Example
Here's a complete example showing how to use the BackendApiService:
Notes
All string amounts in responses are in wei format (18 decimals)
Pagination parameters (
offsetandlimit) are strings, not numbersThe service automatically handles request timeouts and retries
All endpoints return JSON responses
Error messages include HTTP status codes for better debugging
Last updated