576 days ago
Gelato Web3 Functions v. Chainlink Functions
-
At the end of 2022, Gelato launched its Web3 Functions private beta to bring access to off-chain data & computation to web3 developers. At ETHDenver 2023, Chainlink announced a service with a similar name called Chainlink Functions
-
Gelato Web3 Functions and Chainlink Functions address similar problems on the surface, but major differences in each implementation lead to vastly different cost & performance implications for projects
-
The biggest technical difference between the two is that Chainlink Functions use a request/response model while Gelato Web3 Functions use a worker model. This means Chainlink Functions only trigger after someone sends an on-chain transaction that requires paying for gas costs. Gelato’s Web3 Functions on the other hand trigger the execution of W3Fs continuously off-chain, e.g. every minute, and thus being gasless and not requiring to pay for on-chain transactions to run
-
This results in many use cases like the one outlined below enjoying lower latency and gas costs when using Gelato Web3 Functions rather than Chainlink Functions which result in higher latency and higher gas costs
-
Gelato’s Web3 Functions are live on 7 mainnets (Ethereum, Polygon, Optimism, Arbitrum & many more), whereas Chainlink Functions are only available on testnets thus far
What are Gelato Web3 Functions?
Web3 Functions represent a new approach for web3 developers to create serverless applications that eliminate the risk of relying on centralized entities to carry out off-chain computation and becoming the single point of failure.
They can be thought of as decentralized cloud functions that enable web3 developers to:
- Connect their smart contracts to off-chain data by calling arbitrary APIs
- Ensure this data is accurate and is signed off by multiple parties
- Run off-chain computation
- Execute transactions on all major blockchains
- Send notifications triggered by events or state changes
By adopting this innovative approach, developers can forgo traditional centralized platforms like AWS or Google Cloud in favor of a web3-native infrastructure, providing a powerful and scalable solution while maintaining the critical decentralized nature of their projects.
With Web3 Functions, developers can incorporate a reliable, trust-minimized infrastructure into their smart contracts for all server-side components, providing a secure and decentralized foundation for their web3 apps.
Gelato Web3 Functions vs Chainlink Functions
On the surface both services look very similar - the naming, being "serverless" and allowing developers to "connect and access off-chain data". How do they differ? Are they targeting the same use cases? Most importantly - how do they perform in comparison to each other?
The core design difference
Gelato Web3 Functions use a worker model and run continuously off-chain without the need to pay for on-chain gas, whereas Chainlink functions use a request/response model and have to be triggered via on-chain transactions that cost gas.
Chainlink Functions request/response model requires an on-chain transaction to be sent every time an off-chain Chainlink Function should be triggered. The Function, in turn, executes another on-chain transaction to push certain data on-chain. This two-transaction model has the downside of creating latency & gas cost overhead as every Chainlink Function execution requires paying for two on-chain transactions (one to request, one to fulfill).
Using Gelato Web3 Functions, developers can trigger Web3 Functions without requiring any on-chain transaction, making it much more scalable, providing lower latency, and significantly reducing costs. This is because Gelato Web3 Functions can be triggered off-chain. Once developers create a Web3 Function task, the logic is executed automatically in intervals, e.g. every minute. An on-chain transaction to post data on-chain is only required to be executed if a Web3 Function’s logic dictates that a transaction needs to be submitted on-chain.
In addition to this, the integration of a Multichain RPC Provider opens new doors for seamless data fetching across multiple networks. For instance, if you're building on Polygon, you can now easily access data from Arbitrum! This feature simplifies cross-chain communication, making it easier to query data with different blockchains and enable interoperability.
Gelato will soon also support event-driven Web3 Function executions based on arbitrary events emitted on-chain (not only those that inherit e.g. the CL function standard) providing even greater flexibility compared to what Chainlink Functions offer today. This means that projects could automate the triggering of Web3 Functions whenever e.g. a user trades in the WETH / USDC pair on Uniswap.
Costs
Chainlink Functions have three different fees that users have to pay: gas fees, computation (DON) fees, and registry fees. Gas fees can be very high (as shown in the example below) because Chainlink’s request/response model has the drawback of requiring users to pay for two transactions every time a Chainlink Function is run. One to initiate the request and the other one to pay for sending the transaction that fulfills the request after the function was run.
All these fees have to be paid with LINK tokens, which have the downside of being volatile and subject to price fluctuations
Gelato Web3 Function only charges two sets of fees: Gas fees and computation fees (no registry fee). Thanks to Gelato’s worker model, no transactions are required to be sent on-chain in order to trigger Web3 Functions as they get triggered continuously off-chain without the need to pay for on-chain gas.
Instead of charging on-chain transaction fees for running a Web3 Function, Gelato handles the fees that should compensate Gelato Nodes to continuously run Web3 functions using its off-chain multichain 1Balance payment system. Users can subscribe to different tiers that will provide allowances for custom computation needs, the basic package being free.
All Web3 Function costs can simply be paid for using USDC.
Cost Comparison Example
Use case A function that queries the Coingecko price API every minute and updates an on-chain oracle price if it deviates more than 2% from the off-chain Coingecko price.
Assumption: This deviation occurs on average every 20 minutes, meaning 72 times per day.
Results: Using Chainlink Functions, in order to check every minute whether the price of a certain pair on Coingecko deviates from the current on-chain price, the project has to pay for two on-chain transactions every minute, the first to request the function to run off-chain and the second to post its result on-chain.
=> 2 (transactions) x 60 (every minute) x 24 (every hour) = 2.880 transactions per day If you assume an average gas cost of $0.1 per transaction, using Chainlink Functions would cost $288 per day from transaction fees only.
As Gelato Web3 Functions run continuously off-chain, there are no on-chain transaction costs for checking whether the Coingecko price feed differs from the one stored on-chain. Thus, the only on-chain transactions that have to be paid for are the ones that are actually needed in order to update the price, which happens on average every 20 minutes.
Thus:
=> 1 (transaction) x 60 / 20 (every 20 minutes) x 24 (every hour) = 72 transactions per day Assuming the same average gas costs, this would mean using Gelato Web3 Functions for the same use case would only cost $7.2 per day.
This means that using Gelato results in paying 97.5% less for on-chain transactions! Moreover, the off-chain computation costs associated with continuously running Web3 Functions are insignificant compared to the on-chain transaction costs of triggering them continuously.
Developer Friendliness
Chainlink Functions do not support using npm modules which could prove quite restrictive, especially when your function needs to interact with applications such as Uniswap or 1inch which can be very difficult to integrate with.
The code is written in Javascript in both cases. Gelato reads the code from IPFS, whilst Chainlink reads the code from a URL like a Gist or it will be sent by the transaction encoded in bytes. Chainlink Functions limit the source code that is run to not exceed 30 kb which could prove to be unfeasible for larger scripts to be executed, whereas Gelato enables a source code limit of up to 1 MB.
Moreover, Gelato Web3 Function tasks can be created on a user-friendly UI that can be found at https://beta.app.gelato.network/, whereas CL Functions do not have a UI yet.
In-function Features
Both Gelato Web3 Functions and Chainlink Functions enable developers to conduct HTTP Requests and store secrets (e.g. API keys). However, Gelato Web3 Functions have two additional features that can prove to be very useful for developers.
Web3 Functions provide a reliable multichain RPC endpoint out of the box, meaning that developers do not have to worry about signing up to an RPC provider in order to read the state from the respective blockchain and write to it. Additionally, Web3 Functions also provide JSON storage where developers can store & query data, for example, what time the last transaction was executed.
Ease of Integration - Smart Contracts
What does it take to make your smart contract Web3 Function vs Chainlink Function compatible?
In short, Gelato Web3 Functions do not require any changes to existing smart contracts and work for all of them out of the box. The only thing that is advised is to limit the execution of a particular function to only be called by a user’s Gelato dedicated msg.sender. Transactions executed by Gelato also have a very high gas limit that is in most cases equal to the block gas limit.
Using the dedicated msg.sender as a target contract Gelato allows developers with Web3 Functions to execute batched transactions on different contracts simultaneously.
Chainlink Functions on the other hand require deploying entirely new smart contracts that inherit multiple contacts and follow a predefined schema that make them work with the Chainlink Function system, resulting in higher integration friction and the necessity for costly audits. Transactions executed by Chainlink are limited to consuming only up to 300,000 gas.
Network Support
For the time being, both products are in beta, however, Gelato is already deployed on different mainnets and can be used in production today.
The data speaks for itself - Over 1M executions and running
In the first month, Gelato’s Web3 Functions were run over a million times!
Beefy uses Web3 Functions to power two use cases: harvesting their vaults and swapping tokens from the fees accrued using the 1inch API to get the best possible route for their swaps.
“Gelato's Web3 Functions enable our smart contracts to become smarter by combining the power of automation and the ability to access external data. With Web3 Functions we can create more powerful products and also eliminate tedious operational tasks.”- Weso, Lead Developer & Head of Strategic Partnerships at Beefy
Abracadabra has created strategies on different DeFi and Exchanges, and querying 1inch data on-chain to ensure the most optimal routes are used for swaps, withdraws, or buybacks..
"With Gelato Network's Web3 Functions, we automated our yield farming vault's compounding and staking reward buybacks on Abracadabra.money. This streamlined our process and made it easier and more reliable than running our own infrastructure, making it an indispensable tool for our yield farming and lending products."-- Abracadabra
Aavegotchi relies on Web3 Functions to perform regular buybacks of the $GHST token. By utilizing Paraswap’s external APIs, swaps are guaranteed the best possible price as the routing is handled automatically off-chain.
Tangible, long-time power users of Gelato’s automation services have just implemented Web3 Functions to continuously check whether sufficient rent has been collected to be distributed to the real estate token holders as part of their revenue-generating Real Estate NFT’s. When sufficient fees have been collected, Gelato executes the rent payment distribution automatically.
Rysk Finance utilizes Web3 Functions to conduct position-specific monitoring of health factors on various vaults to effectively manage the collateral. When required, Gelato’s Web3 Functions handles the necessary moves of collateral between the vault and liquidity pool automatically. This approach instils confidence in task execution with 100% uptime, abstracting the complexities and resources of Rysk having to handle these processes themselves.
About Gelato
Gelato is a Web3 Cloud Platform empowering developers to create automated, gasless, and off-chain-aware Layer 2 chains and smart contracts. Over 400 web3 projects rely on Gelato for years to facilitate millions of transactions in DeFi, NFTs, and gaming.
-
Gelato RaaS: Deploy your own tailor-made ZK or OP L2 chains in a single click with native Account Abstraction and all Gelato middleware baked in.
-
Web3 Functions: Connect your smart contracts to off-chain data & computation by running decentralized cloud functions.
-
Automate: Automate your smart contracts by executing transactions automatically in a reliable, developer-friendly & decentralized manner.
-
Relay: Give your users access to reliable, robust, and scalable gasless transactions via a simple-to-use API.
-
Account Abstraction SDK: Gelato has partnered with Safe, to build a fully-fledged Account Abstraction SDK, combining Gelato's industry's best gasless transaction capabilities, with the industry's most secure smart contract wallet.
Subscribe to our newsletter and turn on your Twitter notifications to get the most recent updates about the Gelato ecosystem! If you are interested in being part of the Gelato team and building the future of the Internet browse the open positions and apply here.