The TypeScript SDK is the primary way to interact with the Grat relay. It provides a type-safe interface for sponsoring transactions, simulating Soroban contract calls, and monitoring relay health.Documentation Index
Fetch the complete documentation index at: https://grat.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Grat SDK is compatible with Stellar Protocol 26 (Yardstick). Fee estimation and Soroban simulation reflect the latest protocol changes.
Installation
Client Setup
Initialize the Grat client based on your target environment.Constructor Configuration
If you need more control, you can use the standard constructor.| Parameter | Type | Default | Description |
|---|---|---|---|
relayUrl | string | "" | The full URL of your Grat relay server. |
network | "testnet" | "mainnet" | "testnet" | The Stellar network passphrase to use. |
apiKey | string | "" | Your project’s API key (required for mainnet). |
maxRetries | number | 3 | Maximum number of retries for failed requests. |
timeout | number | 30000 | Request timeout in milliseconds. |
Methods
sponsor(transaction)
Wraps a signed transaction in a fee-bump envelope and submits it to the network.
- Parameters:
transaction: Transaction | FeeBumpTransaction - Returns:
Promise<SponsorResult>
sponsorContract(transaction)
An alias for sponsor, specifically labeled for Soroban smart contract transactions.
- Parameters:
transaction: Transaction - Returns:
Promise<SponsorResult>
simulate(transaction)
Simulates a Soroban transaction to get resource fee estimates and diagnostic events.
- Parameters:
transaction: Transaction - Returns:
Promise<SimulationResult>
estimate(transaction)
Returns estimated network fees (Classic and Soroban) for a given transaction.
- Parameters:
transaction: Transaction | FeeBumpTransaction - Returns:
Promise<EstimateResult>
status()
Returns the health status and metadata of the connected relay server.
- Returns:
Promise<HealthStatus>
Phase 2 Methods
The following methods are part of the Phase 2 Credit System and are currently under development.
credits.balance(): Get the current credit balance for your API key.credits.history(): Retrieve a list of recent credit deposits and spend events.credits.depositInfo(): Get instructions for depositing XLM to top up your credits.transactions.list(): List all transactions sponsored by your API key.transactions.get(hash): Get detailed sponsorship metadata for a specific hash.
Response Types
SponsorResult
Error Handling
The SDK throws descriptive errors that can be caught and handled.Automatic Retries
The SDK automatically retries requests that fail due to rate limiting (429) or temporary server issues (503). It uses exponential backoff to avoid overwhelming the relay. You can customize this behavior using themaxRetries option in the client configuration.