How to use Web3 Functions to build serverless web3 apps
Gelato Team
•
Feb 21, 2023

We call our smart contracts 'smart' because they know exactly how to do what we ask them to. Having immutable code that executes as expected is powerful, but the challenge is they don’t know when to execute — and timing is crucial in financial systems.
Since inception, Gelato has enabled web3 developers to automate tasks based on on-chain conditions. Now, Gelato is going one step further with Web3 Functions — decentralized, serverless functions that can communicate both on-chain and off-chain, run any custom logic, and send transactions on-chain.
👉 Learn more in our Web3 Functions blog post.
Decentralized Serverless Functions
Think of Web3 Functions as decentralized versions of AWS Lambda or Google Cloud Functions — but for web3. They let you execute on-chain transactions based on arbitrary off-chain data (APIs, subgraphs, etc.) and computation. Functions are written in TypeScript, stored on IPFS, and run by Gelato Nodes. For details, visit the documentation.
Creating Web3 Functions
To build a decentralized Web3 Function, follow two stages:
Write, test, and deploy the function itself
Create a task that executes the Web3 Function
Writing, Testing & Deploying a Web3 Function
1. Clone the template repo:
2. Configure environment variables:
Edit .env
with your provider RPC URL and optionally a private key:
3. Write your function:
When conditions aren’t met, return:
4. Example: Random API + On-chain Check
5. Test your function locally:
6. Deploy to IPFS:
This returns a CID, which you’ll use to create a task.
Create a Task to Run Your Web3 Function
With your Web3 Function deployed to IPFS, you can now set up a task in the Gelato Web3 Functions UI (currently private beta).
Input the CID, arguments, network, target smart contract, and method
Check source code to verify
Name your task and submit
Gelato Nodes will now handle execution based on your logic and triggers.
Demo App
We’ve built a demo integrating:
Web3 Functions (serverless logic)
Hardhat contracts and deployment scripts
A React frontend
The demo includes a contract with an active
flag and a Web3 Function that calls an external API and executes a transaction when conditions are met. Try it out:
Repo: web3-functions-demo-app
Resources
About Gelato
Gelato is a Web3 Cloud Platform powering automated, gasless, and off-chain-aware smart contracts across major Layer 2 chains. 400+ projects rely on Gelato for millions of DeFi, NFT, and gaming transactions.
Gelato RaaS: Launch ZK or OP rollups with baked-in automation and Account Abstraction.
Web3 Functions: Serverless backend logic for smart contracts.
Automate: Automate smart contracts with triggers.
Relay: Enable gasless transactions via API.
Account Abstraction SDK: Built with Safe, combining gasless infra + secure wallets.
👉 Subscribe to our newsletter and follow us on Twitter.
👉 Explore careers at Gelato to help build the future of Web3.