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.

Your user wants to send USDC to a friend. They do not have XLM, and they should not need it to move their digital dollars. This guide shows you how to build, sign, and sponsor a USDC payment using Grat. You can see this in action on our Live Demo.

Prerequisites

  • A running Grat relay (see the Quickstart).
  • The Grat TypeScript SDK installed.
1

Initialize the SDK

Connect to your local relay.
import { Grat } from '@grat-official-sdk/sdk';
const grat = Grat.testnet();
2

Establish a USDC Trustline

Before a user can receive USDC on Stellar, they must establish a trustline. You can sponsor this setup transaction as well.
import { Asset, TransactionBuilder, Networks, Operation } from '@stellar/stellar-sdk';

const usdc = new Asset("USDC", "GBBD67IFX53O3S6ZDHAYQ4M6Z67G4C3K6G5Y6S6TORYS6A7XNQLS6");

const trustTx = new TransactionBuilder(
  { publicKey: userKp.publicKey(), sequence: "123" },
  { fee: "100", networkPassphrase: Networks.TESTNET }
)
.addOperation(Operation.changeTrust({ asset: usdc }))
.setTimeout(30)
.build();

trustTx.sign(userKp);
await grat.sponsor(trustTx);
3

Build a USDC Payment

Build a standard payment transaction. Note that you don’t need to worry about Alice having XLM for the fee, as Grat will cover it.
const paymentTx = new TransactionBuilder(
  { publicKey: senderKp.publicKey(), sequence: "124" },
  { fee: "100", networkPassphrase: Networks.TESTNET }
)
.addOperation(Operation.payment({
  destination: receiverPublicKey,
  asset: usdc,
  amount: "10.00"
}))
.setTimeout(30)
.build();
4

Sign and Sponsor

Alice signs the transaction to authorize the payment, then your app sends it to Grat for sponsorship.
paymentTx.sign(senderKp);

console.log("Sponsoring USDC payment...");
const result = await grat.sponsor(paymentTx);

console.log("Success! Hash:", result.hash);
5

Verify the Payment

Verify the transaction hash on Stellar Expert. The record will show that Alice’s balance decreased by 10 USDC, while Grat’s channel account paid the native XLM fee.
This guide uses the Testnet USDC issuer address. For Mainnet, you must use the official Circle USDC issuer address.
View on GitHub