Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md

Relayer Sponsored Example

This example demonstrates how to use Gelato's Turbo Relayer for gasless transactions with sponsored payments.

Overview

The Relayer is the simplest integration path - it relays transactions directly without requiring a smart account. Gelato pays the gas fees (sponsored mode).

Prerequisites

Setup

  1. Install dependencies:

    pnpm install
  2. Configure environment variables (see Environment Variables section below)

Environment Variables

This example loads environment variables from two sources:

  1. Root .env (at project root) - Shared defaults for all examples
  2. Local .env (in this directory) - Optional overrides

Local values take precedence over root values. To set up:

  1. Copy the root .env.example to .env at the project root:

    cp ../../../.env.example ../../../.env
  2. Add your API key to the root .env:

    GELATO_API_KEY="your-api-key"
    
  3. (Optional) Create a local .env in this directory to override specific values for this example

Run

pnpm dev

Code Walkthrough

Step 1: Create the Relayer Client

const relayer = createGelatoEvmRelayerClient({
  apiKey: GELATO_API_KEY,
  testnet: chain.testnet
});

Creates a relayer client configured for Base Sepolia testnet.

Step 2: Send a Sponsored Transaction

const id = await relayer.sendTransaction({
  chainId: chain.id,
  data: '0xd09de08a',
  to: '0xE27C1359cf02B49acC6474311Bd79d1f10b1f8De'
});

Submits a transaction to Gelato. Your Gelato Gast Tank covers gas costs.

Step 3: Wait for Confirmation

const status = await relayer.waitForStatus({ id });

if (status.status === StatusCode.Success) {
  console.log(`Transaction hash: ${status.receipt.transactionHash}`);
}

Polls until the transaction reaches a final state (Success, Rejected, or Reverted).

Key Concepts

Concept Description
sponsored() Gelato pays gas fees
sendTransaction Async - returns immediately with ID
waitForStatus Blocks until transaction is finalized
StatusCode.Success Transaction successfully included on-chain