Gelato
  • Introduction
    • Gelato, The Web3 Cloud Platform
  • Rollup As A Service
    • Introduction
    • Rollup Stacks
      • Arbitrum Orbit
        • Run a Full Orbit Node
      • OP Stack
        • Run OP Node
    • Deploy your Rollup
    • Customization
      • Data Availability
        • Celestia
        • Avail
        • Eigen DA
      • Custom Gas Token
      • Marketplace
        • Gelato Services
        • Data Indexers
        • Block Explorers
        • Oracles
        • Bridges
        • Account Abstraction
        • On & Off-ramp
        • Community
        • Identity & KYC
        • Others
      • Verifier Node Package
    • Public Testnet
  • RPC Nodes
    • Introduction
    • Compute Units
    • Using RPC Nodes
    • Supported Networks
    • Pricing and Plans
    • FAQ
  • Web3 Services
    • Web3 Functions
      • Understanding Web3 Functions
        • Trigger Types
        • Typescript Function
        • Solidity Function
        • Automated Transactions
      • Security Considerations
      • Template & Use Cases
      • Quick Start
        • Writing Typescript Functions
          • Event Trigger
          • Private Typescript Functions
          • Callbacks
        • Test, Deploy & Run Typescript functions
        • Writing Solidity Functions
        • Test, Deploy & Run Solidity Functions
        • Initiate an Automated Transaction
      • Create a Web3 Function Task
        • Using the UI
        • Using the Safe App
        • Using a Smart Contract
        • Using the Automate SDK
      • Analytics & Monitoring
      • Supported Networks
      • Subscription & Payments
      • Legacy Automate Migration Guide
    • Relay
      • What is Relaying?
      • Security Considerations
        • ERC-2771 Delegatecall Vulnerability
      • Templates
      • Quick Start
        • Sponsored Calls
        • Non-Sponsored Calls
      • ERC-2771 (recommended)
        • SponsoredCallERC2771
        • CallWithSyncFeeERC2771
          • Relay Context Contracts ERC2771
      • Non-ERC-2771
        • SponsoredCall
        • CallWithSyncFee
          • Relay Context Contracts
      • Relay API
      • Gelato's Fee Oracle
      • Tracking your Relay Request
      • Supported Networks
      • Subscriptions and Payments
        • 1Balance & Relay
        • SyncFee Payment Tokens
        • Relay Pricing
      • ERC2771 Migration Guide
    • VRF
      • Understanding VRF
      • How does Gelato VRF Work?
      • Security Considerations
      • Template
      • Quick Start
      • Create a VRF Task
        • Create a Fallback VRF
        • Migrating from Chainlink VRF
      • Supported Networks
      • Pricing & Rate Limits
    • Oracles
      • Understanding Gelato Oracles
      • Quick Start
      • Data Providers
        • Stork
        • Choas Labs
      • Migrating from Chainlink Oracles
      • Available Price Feeds
      • Supported Networks
      • Pricing & Rate Limits
    • Account Abstraction
      • Understanding ERC4337
      • Introduction to Gelato Bundler
      • Templates & Examples
      • Quick Start
      • Sponsored UserOps
        • Using 1Balance
        • Using Zerodev Paymaster
      • Non-Sponsored UserOps
        • Pay with Native
        • Pay with ERC20
      • Supported Networks
      • Bundler API Endpoints
        • eth_sendUserOperation
        • eth_estimateUserOperationGas
        • eth_getUserOperationByHash
        • eth_getUserOperationReceipt
        • eth_supportedEntryPoints
        • eth_maxPriorityFeePerGas
        • eth_chainId
    • 1Balance
      • 1Balance Alerts
      • Subscription Plans
      • Subscription Notifications
      • USDC Addresses
    • AI Agents
    • Teams
  • GELATO DAO
    • DAO & Token (GEL)
    • GEL Token Contracts
    • Governance Process
  • Social Media
Powered by GitBook
On this page
  • Initial Steps
  • 1. Create Your Gelato Account
  • 2. Create a Relay App
  • 3. Retrieve Your Sponsor API Key
  • 4. Deposit Funds into 1Balance
  • Implementation Steps
  • 1. Import GelatoRelaySDK into your front-end .js project
  • 2. Deploy a smart contract
  • 3. Generate a payload for your target contract
  • 4. Send the payload to Gelato
  1. Web3 Services
  2. Relay
  3. Quick Start

Sponsored Calls

PreviousQuick StartNextNon-Sponsored Calls

Last updated 1 month ago

Sponsored Calls enable you to cover your users' gas fees, providing a seamless and gasless experience for interacting with your dApp. This is made possible through Gelato's multi-chain unified gas payment system, 1Balance. Learn more about 1Balance .

Initial Steps

1. Create Your Gelato Account

Sign up on the to establish an account. This account is the foundation for setting up relay tasks and managing gas sponsorships.

2. Create a Relay App

Within your Gelato account, create a relay app on the specific network where you plan to sponsor transactions. This step enables sponsored transactions on your chosen chain. Checkout supported networks .

3. Retrieve Your Sponsor API Key

After creating the relay app, navigate to its dashboard to locate your Sponsor API Key. This key links your Gelato setup with 1Balance for gas sponsorship.

Gelato Relay now supports API key rotation, allowing users to create and delete API keys. This helps prevent unauthorized usage in case an API key is exposed.

4. Deposit Funds into 1Balance

Add funds to your 1Balance account according to your target environment:

  • Mainnets: Deposit USDC.

  • Testnets: Deposit Sepolia ETH.

Implementation Steps

1. Import GelatoRelaySDK into your front-end .js project

import SponsoredCallRequest for Non ERC2771 sponsored calls with GelatoRelay.

import { GelatoRelay, SponsoredCallRequest } from "@gelatonetwork/relay-sdk";
const relay = new GelatoRelay();

or

If you’re using the Viem library in your project, consider importing @gelatonetwork/relay-sdk-viem.

import { GelatoRelay, SponsoredCallRequest } from "@gelatonetwork/relay-sdk-viem";
const relay = new GelatoRelay();

For ERC2771 Sponsored Calls (Recommended)

import { GelatoRelay, CallWithERC2771Request } from "@gelatonetwork/relay-sdk-viem";
import { GelatoRelay, CallWithERC2771Request } from "@gelatonetwork/relay-sdk";

Once we have imported the GelatoRelay class, when using ERC2771 methods, we must initialize it with the appropriate trustedForwarder. The possible configurations are:

  contract: {
    relay1BalanceERC2771: "trustedForwarder for method sponsoredCallERC2771",
    relayERC2771: "trustedForwarder for method callWithSyncFeeERC2771",
    relay1BalanceConcurrentERC2771: "trustedForwarder for method concurrent sponsoredCallERC2771",
    relayConcurrentERC2771:"trustedForwarder for method concurrent callWithSyncFeeERC2771",
    relay1BalanceConcurrentERC2771zkSync: "trustedForwarder for method concurrent sponsoredCallERC2771 on zkSync",
    relay1BalanceERC2771zkSync: "trustedForwarder for method sponsoredCallERC2771 on zkSync",
    relayConcurrentERC2771zkSync: "trustedForwarder for method concurrent callWithSyncFeeERC2771 on zkSync",
    relayERC2771zkSync: "trustedForwarder for method callWithSyncFeeERC2771 on zkSync",
  },
const relay = new GelatoRelay({
contract: {
    relay1BalanceERC2771:"0xd8253782c45a12053594b9deB72d8e8aB2Fca54c"
    }
});

2. Deploy a smart contract

For non-ERC2771 sponsored calls, no modifications are required in your target contract. Below is an example of a target contract.

contract TargetContract {
    // your logic
    function example() external {
        // your logic
    }
}

For ERC2771 Sponsored Calls

import {
    ERC2771Context
} from "@gelatonetwork/relay-context/contracts/vendor/ERC2771Context.sol";

contract TargetContract is ERC2771Context {
    // ERC2771Context: setting the immutable trustedForwarder variable
    constructor(address trustedForwarder) ERC2771Context(trustedForwarder) {}
    function example() external{
        // your logic
    }
}

3. Generate a payload for your target contract

// set up target address and function signature abi
const targetContractAddress = "your target contract address";
const abi = ["function example()"];

const [address] = await window.ethereum!.request({
      method: "eth_requestAccounts",
 });

// generate payload using front-end provider such as MetaMask
const client = createWalletClient({
      account: address,
      chain,
      transport: custom(window.ethereum!),
});
const chainId = await client.getChainId();

//encode function data
const data = encodeFunctionData({
    abi: abi,
    functionName: "example",
});
// set up target address and function signature abi
const targetContractAddress = "target contract address"; 
const abi = ["function example()"];

// generate payload using front-end provider such as MetaMask
const provider = new ethers.BrowserProvider(window.ethereum);
const signer = provider.getSigner();
const user = await signer.getAddress();

const contract = new ethers.Contract(targetContractAddress, abi, signer);

const { data } = await contract.populateTransaction.example();

4. Send the payload to Gelato

// Populate a relay request
const request: SponsoredCallRequest = {
  chainId: BigInt(chainId),
  target: targetContractAddress,
  data: data as BytesLike,
};
const relayResponse = await relay.sponsoredCall(
    request,
    GELATO_RELAY_API_KEY
);
// Populate a relay request
const request: SponsoredCallRequest = {
  chainId: (await provider.getNetwork()).chainId,
  target: targetContractAddress,
  data: data,
};

const relayResponse = await relay.sponsoredCall(request, apiKey);

For ERC2771 Sponsored Calls

// Populate a relay request
const request : CallWithERC2771Request = {
    user: address,
    chainId: BigInt(chainId),
    target: targetContractAddress,
    data: data as BytesLike,
};

const response = await relay.sponsoredCallERC2771(
    request,
    client as any,
    GELATO_RELAY_API_KEY
);
// Populate a relay request
const request: CallWithERC2771Request = {
  chainId: (await provider.getNetwork()).chainId,
  target: targetContractAddress;
  data: data;
  user: user;
};

const relayResponse = await relay.sponsoredCallERC2771(request, signer, apiKey);

Since 1Balance is deployed on Polygon, you can deposit USDC in one step, and deposits from other networks are supported via Circle CCTP. Learn .

import CallWithERC2771Request for ERC2771 sponsored calls with GelatoRelay. Learn more about ERC2771 .

We will need to go to the and check the network and the contract addresses to identify the trustedForwarder associated with our method. In the example below, we are using the method sponsoredCallERC2771 on Sepolia, the trustedForwarder associated is 0xd8253782c45a12053594b9deB72d8e8aB2Fca54c. We will initialize GelatoRelay with the following config:

Import ERC2771Context into your target contract and initialize it in the constructor with the appropriate trusted forwarder based on your use case. checkout list of trusted forwarders .

Learn more about implementation of ERC2771 Sponsored Calls and Non ERC2771 Sponsored Calls .

more
here
Supported Networks
here
here
here
here
Gelato App
here