Skip to main content
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.
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.

Methods

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 the maxRetries option in the client configuration.

End-to-End Example: USDC Payment

View on GitHub