Skip to main content

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.

Get started with Grat by setting up a local relay and sponsoring a testnet transaction.

Prerequisites

  • Docker installed and running.
  • Node.js 20+ and a package manager (npm, yarn, or pnpm).
1

Start the Relay

To sponsor transactions, you need a running Grat Relay.Deploy a private relay to Render in minutes. This provides an instant HTTPS endpoint for your web apps.Deploy to Render

Option B: Local Docker

If you prefer to run it locally:
git clone https://github.com/gratnetwork/grat.git
cd grat
docker-compose up -d
The relay will automatically fund its internal channel accounts using the Stellar Friendbot when running in testnet mode.
2

Install the SDK

In your project directory, install the official TypeScript SDK.
npm install @grat-official-sdk/sdk
3

Sponsor your first Transaction

Create a file named sponsor.ts and add the following code. This script builds a simple XLM payment on the testnet and sends it to the Grat relay for sponsorship.
import { Grat } from '@grat-official-sdk/sdk';
import { Keypair, Asset, TransactionBuilder, Networks, Operation } from '@stellar/stellar-sdk';

async function main() {
  // 1. Initialize the Grat client for testnet
  const grat = Grat.testnet();

  // 2. Create a test account (the user)
  const userKp = Keypair.random();
  
  // 3. Build a simple XLM payment transaction
  // Note: In a real app, you would load the account to get the current sequence number
  const tx = new TransactionBuilder(
    { publicKey: userKp.publicKey(), sequence: "1" },
    { fee: "100", networkPassphrase: Networks.TESTNET }
  )
  .addOperation(Operation.payment({
    destination: "GDQP237HAYA6AK3AOTK2S3SFSBCS3KZ766XJH5Y6S6TORYS6A7XNQLS6",
    asset: Asset.native(),
    amount: "10"
  }))
  .setTimeout(30)
  .build();

  // 4. Sign the transaction with the user's keypair
  tx.sign(userKp);

  // 5. Sponsor and submit via Grat
  console.log("Sponsoring transaction...");
  const result = await grat.sponsor(tx);

  console.log("Success! Transaction hash:", result.hash);
}

main();
4

Verify it Worked

Copy the transaction hash from your console and search for it on Stellar Expert (Testnet). You will see that the transaction was successful and that a fee-bump envelope was used to pay the network fee.
Ready for something more realistic? Check out our guide on Sponsoring USDC Payments to see how to handle trustlines and asset transfers.
View on GitHub