Gelato
  • Introduction
    • Gelato, The Web3 Cloud Platform
  • Smart Wallets
    • Introduction
      • Understanding EIP-7702
      • Understanding ERC-4337
      • ERC-4337 vs EIP-7702
    • Templates & Examples
    • How-To Guides
      • Create a Sponsor API Key
      • Sponsor gas for your users
      • Allow users to pay gas with erc20
      • Allow users to pay gas with native
      • Create Dynamic's Environment Id
      • Use Dynamic/Privy signers with React SDK
      • Estimate Gas for your transactions
    • React SDK
    • Demo
    • Supported Networks
  • 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 ERC-4337
      • Introduction to Gelato Bundler
      • Templates & Examples
      • Quick Start
      • 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
  • Overview
  • Using Safe smart contract wallets for sponsoredCall
  • Sending a Request
  • Request Body
  • Example Code
  • 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. Non-ERC-2771

SponsoredCall

Permissionless sponsored transactions

PreviousNon-ERC-2771NextCallWithSyncFee

Last updated 1 month ago

After reading this page:

  • You'll know how to use theSponsoredCallSDK method. This uses the payment method, allowing you to sponsor some/all of your user's gas costs.

  • You'll see some code which will help you send a relay request within minutes.

Please proceed to our page and read it thoroughly before advancing with your implementation. It is crucial to understand all potential security risks and measures to mitigate them.

The nature of sponsoredCall is permissionless and does not enforce any security. Target contracts should not whitelist the calling contract as an authorized msg.sender. The contract address is subject to change without further notice.

Overview

sponsoredCall method utilises authentication via a sponsor API key to sponsor gasless transactions for your users securely. The payment method is Gelato .

SDK method: sponsoredCall

const sponsoredCall = async (
  request: SponsoredCallRequest,
  sponsorApiKey: string,
  options?: RelayRequestOptions
): Promise<RelayResponse>

Arguments:

  • request: this is the used to send a request.

  • sponsorApiKey : an API key used to authenticate your sponsorship.

  • options: RelayRequestOptions is an optional request object.

Return Object: RelayResponse

type RelayResponse = {
  taskId: string;
};

Optional Parameters

type RelayRequestOptions = {
  gasLimit?: BigNumberish;
  retries?: number;
};
  • gasLimit: the gas limit of the relay call. This effectively sets an upper price limit for the relay call.

    • If you are using your own custom gas limit, please add a 150k gas buffer on top of the expected gas usage for the transaction. This is for the Gelato Relay execution overhead, and adding this buffer reduces your chance of the task cancelling before it is executed on-chain.

    • If your contract has any hardcoded requirements about gas usage, please always explicitly pass the gasLimit to the SDK/API, as Gelato will not know what hardcoded gas expectations your contract has. Otherwise, your relay requests might not be executable.

  • retries: the number of retries that Gelato should attempt before discarding this relay call. This can be useful if the state of the target contract is not fully known and such reverts can not be definitively avoided.

Using Safe smart contract wallets for sponsoredCall

If you need to dispatch transactions from Safe smart contract wallets using Gelato Relay via sponsoredCall, you can opt to activate Safe-enabled transactions in your Relay Dapp configuration.

Usually when submitting Gelato Relay transactions that originate from Safe smart contract wallets, the Safe wallet address is specified in the target field of the Relay API request, whereas both the actual target contract address and its calldata are encoded into the execTransaction payload. By activating Safe-enabled transactions - accomplished by checking the "Allow sponsored transactions from Safes" box - Gelato Relay will validate your Safe smart contract and decode the target contract address and function selector from the execTransaction calldata. It will then apply your pre-configured Relay Dapp rules to these values, rather than to the values given in the Relay request.

If your intention is to deploy Safe smart contract wallets prior to their usage, be sure to whitelist the multicall contract address in your Relay Dapp. This contract is typically invoked when you deploy a Safe smart contract wallet before it can be used for the first time.

Sending a Request

Request Body

const request = {
  chainId: BigNumberish;
  target: string;
  data: BytesLike;
};
  • chainId: the chain ID of the chain where the target smart contract is deployed.

  • target: the address of the target smart contract.

  • data: encoded payload data (usually a function selector plus the required arguments) used to call the required target address.

Example Code

Since sponsoredCall assumes you have your own security logic built in (i.e. replay and re-entrancy protection), you can go ahead and generate the payload for your function call and populate a request object.

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

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

2. Deploy a smart contract

pragma solidity 0.8.17;

contract SimpleCounter {
    uint256 public counter;

    event IncrementCounter(uint256 newCounterValue, address msgSender);

    // `increment` is the target function to call.
    // This function increments a counter variable by 1
    // IMPORTANT: with `sponsoredCall` you need to implement 
    // your own smart contract security measures, as this 
    // function can be called by any third party and not only by 
    // Gelato Relay. If not done properly, funds kept in this
    // smart contract can be stolen.
    function increment() external {
        counter++;
        emit IncrementCounter(counter, msg.sender);
    }
}

3. Generate a payload for your target contract

// set up target address and function signature abi
const counter = "0x763D37aB388C5cdd2Fb0849d6275802F959fbF30"; 
const abi = ["function increment()"];

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

const contract = new ethers.Contract(counterAddress, abi, signer);
const { data } = await contract.increment.populateTransaction();

4. Send the payload to Gelato

// Populate a relay request
const request: SponsoredCallRequest = {
  chainId: (await provider.getNetwork()).chainId,
  target: counter,
  data: data,
};

// Without a specific API key, the relay request will fail! 
// Go to https://relay.gelato.network to get a testnet API key with 1Balance.
// Send the relay request using Gelato Relay!
const relayResponse = await relay.sponsoredCall(request, apiKey);

taskId: your unique relay task ID which can be used for .

This is an example using Gelato's SimpleCounter.sol which is deployed on and .

tracking your request
Goerli
Polygon
Security Considerations
1Balance
request body
Allow sponsored transactions from Safes
1Balance