Gelato Network Integration (Automation)
Blockchain doesn't run functions on a schedule. If a contract needs to rebalance a pool every 24 hours, accrue staking rewards, or liquidate positions — someone must call these functions from outside. Gelato Network is a decentralized network of bots (executors) that monitor conditions and send transactions automatically.
Two Modes of Operation
Gelato Automate (old approach, Ops). A task is created via UI or SDK, an executor calls the specified function on schedule or condition. Payment in GELATO (native token) or ETH from the contract balance.
Web3 Functions (current standard). An off-chain JavaScript/TypeScript function that runs on Gelato nodes, can make HTTP requests, read off-chain data, and returns calldata for an on-chain transaction. This solves the problem where decision-making requires data outside the chain — price on CEX, API request result, data from The Graph.
Integration via AutomateTaskCreator
Inheriting from AutomateTaskCreator gives a contract the ability to create Gelato tasks programmatically:
import {AutomateTaskCreator} from "@gelatonetwork/automate-sdk/contracts/AutomateTaskCreator.sol";
contract MyVault is AutomateTaskCreator {
bytes32 public rebalanceTaskId;
constructor(address _automate, address _taskCreatorProxy)
AutomateTaskCreator(_automate, _taskCreatorProxy) {}
function startRebalancing() external onlyOwner {
ModuleData memory moduleData = ModuleData({
modules: new Module[](2),
args: new bytes[](2)
});
moduleData.modules[0] = Module.TIME;
moduleData.modules[1] = Module.PROXY;
moduleData.args[0] = _timeModuleArg(block.timestamp, 1 days);
moduleData.args[1] = _proxyModuleArg();
rebalanceTaskId = _createTask(
address(this),
abi.encodeCall(this.rebalance, ()),
moduleData,
address(0) // pay in ETH from contract
);
}
function rebalance() external onlyDedicatedMsgSender {
// rebalance logic
}
}
onlyDedicatedMsgSender — important modifier: only Gelato can call this function, not any arbitrary address.
Gasless Execution (Relay)
Gelato Relay allows users to send transactions without ETH — Gelato pays for gas, and the contract compensates via ERC-20 tokens through _transferRelayFee():
import {GelatoRelayContextERC2771} from "@gelatonetwork/relay-sdk/contracts/GelatoRelayContextERC2771.sol";
contract GaslessNFT is GelatoRelayContextERC2771 {
function safeMint(address to) external onlyGelatoRelayERC2771 {
_mint(to, tokenId++);
_transferRelayFee(); // pay Gelato from contract balance
}
}
ERC2771 part: the user signs a transaction off-chain, Gelato relays it through a trusted forwarder, the contract sees the real _msgSender() via ERC-2771 context.
Web3 Functions for Off-Chain Logic
A TypeScript script runs on Gelato nodes and can:
import { Web3Function, Web3FunctionContext } from "@gelatonetwork/web3-functions-sdk";
Web3Function.onRun(async (context: Web3FunctionContext) => {
const { multiChainProvider, secrets } = context;
const provider = multiChainProvider.default();
// Get data from external API
const response = await fetch("https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd");
const { ethereum } = await response.json();
if (ethereum.usd < 2000) {
const contract = new ethers.Contract(VAULT_ADDRESS, VAULT_ABI, provider);
const callData = contract.interface.encodeFunctionData("triggerEmergency", []);
return { canExec: true, callData: [{ to: VAULT_ADDRESS, data: callData }] };
}
return { canExec: false, message: "Price above threshold" };
});
Payment and Economics
Gelato charges a fee on top of gas cost. For Automate: balance is replenished in ETH on the contract or in Gelato Treasury. For Relay: fee is ~10% of gas cost. For Web3 Functions: additional charge for computation.
On high-load tasks (liquidations, arbitrage), Gelato competes with Chainlink Automation and custom keeper bots. For tasks with moderate frequency (once per hour to once per day), Gelato is optimal in terms of integration simplicity vs cost.
Timelines
Basic Automate integration with time-based task: 1 day. Web3 Function with off-chain logic and Relay: 2-3 days. Testing on testnet (Gelato supports Sepolia, Mumbai/Amoy, Arbitrum Goerli) included in the estimate.
Cost is calculated after clarifying task frequency and off-chain logic complexity.







