Introducing Web3 Functions: Building Serverless Web3 Apps

Gelato Team

Mar 1, 2023

Web3 Functions are a new paradigm enabling developers to build web3 apps that run entirely serverless, without creating a single point of failure or relying on a centralized party for correct computation.

They act as decentralized cloud functions that allow developers to:

  • Connect smart contracts to off-chain data

  • Ensure this data is verified and signed by multiple parties

  • Run off-chain computation

  • Execute transactions on all major blockchains

  • Send notifications triggered by events or state changes

  • Index and store data such as events and transaction receipts

The goal of Web3 Functions is to provide developers with a web3-native alternative to running server-side logic on centralized platforms like AWS or Google Cloud. With Web3 Functions, developers can extend their smart contracts using a scalable, trust-minimized backend without sacrificing decentralization.

How Web3 Functions Work

Architecture of Web3 Functions

Writing a Web3 Function is similar to writing a traditional cloud function, except the code is stored on IPFS and executed by Gelato Nodes. Developers can use the Web3 Functions template to write logic in TypeScript (e.g., fetching data from an API, running computations, or preparing on-chain transactions).

After testing locally, developers deploy the code to IPFS and receive an IPFS ID. Gelato Nodes can then be instructed to run this function based on triggers such as:

  • Time intervals (e.g., every minute)

  • On-chain events

  • Webhooks

Once invoked, multiple Gelato Nodes execute the logic, agree on the results, and prepare an on-chain transaction if needed. The number of Nodes required to sign off on data is configurable by the creator, with non-deterministic data (e.g., prices) aggregated differently from deterministic data (e.g., subgraph queries).

In this way, Web3 Functions expand the role of oracles beyond price feeds into full-fledged decentralized backends for web3 apps.

Technical Features

  • TypeScript with Deno runtime

  • RPC provider abstraction

  • Access to environment variables and secrets

  • Private or public deployment (via IPFS)

  • In-function state management

  • Pay-per-usage pricing

  • High scalability

  • Spawn new Web3 Functions from on-chain transactions

👉 Check out our developer tutorial for a hands-on guide.

Example: Sports Betting Platform

Suppose you’re building a sports betting dApp where payouts depend on real-world match results. Web3 Functions let you fetch match data from off-chain APIs and trigger smart contract calls on-chain when conditions are met.

import { Web3Function, Web3FunctionContext } from "@gelatonetwork/web3-functions-sdk";
import { utils } from "ethers";
import axios from "axios";

Web3Function.onRun(async (context: Web3FunctionContext) => {
  const gameId = (context.userArgs.gameId as string) ?? "Argentina_vs_France";

  let gameEvent;
  try {
    const api = `https://www.thesportsdb.com/api/v1/json/3/searchevents.php?e=${gameId}`;
    const res = await axios.get(api);
    gameEvent = res.data.event[0];
  } catch {
    return { canExec: false, message: `API call failed` };
  }

  if (gameEvent.strStatus !== "Match Finished") {
    return { canExec: false, message: `Match not finished yet` };
  }

  const BETTING_CONTRACT_ABI = ["function updateGameScore(string,uint16,uint16)"];
  const bettingInterface = new utils.Interface(BETTING_CONTRACT_ABI);

  const callData = [{
    to: context.userArgs.targetContract,
    data: bettingInterface.encodeFunctionData("updateGameScore", [
      gameId,
      parseInt(gameEvent.intHomeScore),
      parseInt(gameEvent.intAwayScore),
    ]),
  }];

  return { canExec: true, callData };
});

Further Use Cases

  • Streaming-based music royalty payouts (e.g., Spotify plays)

  • Automated trading strategies accessing DEX aggregator APIs (e.g., 1inch, Paraswap)

  • Resolving prediction markets with real-world data

  • Pushing NFT floor price feeds on-chain

  • Liquidity management strategies powered by AI models

  • Large-scale liquidation systems monitoring borrower positions

About Gelato

Gelato is a Web3 Cloud Platform powering automated, gasless, and off-chain-aware Layer 2 chains and smart contracts. Over 400 projects trust Gelato to execute millions of transactions across DeFi, NFTs, and gaming.

  • Gelato RaaS: Deploy ZK or OP rollups with built-in Account Abstraction and middleware.

  • Web3 Functions: Serverless backend logic for smart contracts.

  • Automate: Automate smart contracts with custom triggers.

  • Relay: Enable gasless transactions via API.

  • Account Abstraction SDK: Developed with Safe, combining gasless infra and secure wallets.

👉 Subscribe to our newsletter and follow Gelato on Twitter.
👉 Explore careers at Gelato and help build the future of Web3.

Ready to build?

Start with a testnet, launch your mainnet in days, and scale with industry-leading UX.

Ready to build?

Start with a testnet, launch your mainnet in days, and scale with industry-leading UX.

Ready to build?

Start with a testnet, launch your mainnet in days, and scale with industry-leading UX.

Ready to build?

Start with a testnet, launch your mainnet in days, and scale with industry-leading UX.