Skip to content

gratnetwork/grat

Repository files navigation

Grat Logo

Grat: Stellar Fee-Sponsorship Relay

Eliminate the "XLM for Gas" problem and onboard users to Stellar with zero friction.

npm version Documentation

What is Grat?

Stellar transactions require XLM to pay for network fees. For many users, especially those only interested in stablecoins (like USDC), acquiring XLM is a high-friction barrier to entry.

Grat is a relay server and SDK that implements Gas Abstraction. It allows developers to sponsor the transaction fees for their users by wrapping transactions in fee-bump envelopes. With Grat, your users can hold USDC and perform operations without ever needing to touch or even know about XLM. Try the Live Demo

Compatible with Protocol 26 (Yardstick), including all new Soroban host functions, precise TTL extensions, and frozen ledger entry handling.


Quick Start

1. Start the Relay

Option A: One-Click Cloud Deploy (Recommended)

Deploy your own private relay to the cloud in minutes:

Deploy to Render

Option B: Local Docker

Clone the repo and start the local stack in under 2 minutes:

git clone https://github.com/gratnetwork/grat.git
cd grat
cp .env.example .env
# Open .env and add your STELLAR_FUNDING_SECRET
docker-compose up -d

2. Install the SDK

npm install @grat-official-sdk/sdk

3. Sponsor a Transaction

import { Grat } from '@grat-official-sdk/sdk';

const grat = Grat.testnet(); // Defaults to http://localhost:3000
const result = await grat.sponsor(signedUserTransaction);

console.log(`Success! Sponsored Hash: ${result.hash}`);

How It Works

Grat leverages Stellar's native Fee-Bump Transactions (CAP-0015).

  1. The user signs a standard transaction (the "inner" transaction).
  2. The SDK sends this to the Grat Relay.
  3. The Relay selects an available Channel Account from a pre-funded pool.
  4. The Relay wraps the inner transaction in a Fee-Bump envelope, signs it with the channel account, and submits it to the network via Stellar RPC.
  5. Deep Error Diagnostics: If a transaction fails, Grat drills down into the inner results to expose the exact operation error (e.g., op_low_reserve, op_no_issuer), saving developers hours of debugging.
  6. Redis-backed sequence management ensures high concurrency without sequence conflicts across multiple instances.
  7. Protocol 26 (Yardstick) Ready: Fully supports Stellar RPC from day one, handling all new Soroban host functions, precise TTL extensions, and frozen ledger entry rejections (CAP-0077) with distinct error codes.

SDK Reference

Grat Client

Method Description
sponsor(tx) Wraps a signed transaction and submits it. Returns { hash, ledger, feePaid }.
simulate(tx) Performs Soroban simulation via the relay to return resource estimates.
estimate(tx) Predicts the total fee (inclusion + resource) for a transaction.
status() Returns relay health, network info, and channel pool statistics.

API Reference

POST /v1/sponsor

Sponsor a classic or Soroban transaction.

  • Body: { "transaction": "BASE64_XDR", "network": "testnet" }
  • Headers: X-Idempotency-Key (Optional, recommended)
  • Response: 200 OK with SponsorResponse object.

POST /v1/simulate

Simulate a Soroban transaction to get execution footprints and resource costs. Works for both classic and Soroban transactions (classic returns zero costs).

  • Body: { "transaction": "BASE64_XDR" }

Self-Hosting

Grat is designed to be horizontally scalable and production-ready.

Environment Variables

  • RPC_URL: URL of your Stellar RPC provider (Default: https://soroban-testnet.stellar.org).
  • STELLAR_FUNDING_SECRET: Master key used to fund and create the channel pool.
  • CHANNEL_SEED_PHRASE: 12-word BIP39 mnemonic or secret used to derive channel keys.
  • CHANNEL_COUNT: Number of accounts in the pool (Default: 10).
  • REDIS_URL: URL for Redis (Required for locking and sequence tracking).
  • DATABASE_URL: PostgreSQL connection string (Required for transaction logging).
  • NETWORK: testnet or mainnet.

Examples (Verified Phase 1)

Explore the examples/ directory for production-ready blueprints:


Running Tests

pnpm install
pnpm test:unit         # Run SDK unit tests
pnpm test:integration  # Run Server integration tests against testnet
pnpm smoke-test        # Run end-to-end network validation

Phase 1 Status: [Stable & Verified]

Grat has completed its Phase 1 milestone. All core gas-abstraction features for both Stellar Classic and Soroban are implemented, tested, and verified on Testnet.

  • Classic Transaction Sponsorship
  • Soroban Resource Fee Sponsorship
  • Distributed Sequence Management
  • High-Concurrency Channel Pool
  • Deep Error Diagnostics
  • Multi-platform SDK (TypeScript)
  • Protocol 26 (Yardstick) Compatibility

Contributing

We welcome contributions! Please check the Contributing Guide and our Code of Conduct.

Contact & Support

License

Apache 2.0 © Grat Network

About

Grat is a relay server and SDK that implements Gas Abstraction. It allows developers to sponsor the transaction fees for their users by wrapping transactions in fee-bump envelopes. With Grat, your users can hold USDC and perform operations without ever needing to touch or even know about XLM.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages