---
name: thyme-migrate-gelato
description: Port Gelato Web3 Functions (and Gelato Automate tasks) to Thyme Flow. Use when a repository contains `@gelatonetwork/web3-functions-sdk`, `Web3Function.onRun`, `w3f test` or `w3f deploy`, `@gelatonetwork/automate-sdk`, or contracts using `AutomateReady` or `dedicatedMsgSender`, or when the user asks to move off Gelato automation. Covers finding the functions and their triggers, translating the code, testing locally and handing over to the thyme-flow skill for upload and scheduling.
---

# Migrate Gelato Web3 Functions to Thyme Flow

Gelato shut down Web3 Functions and Automate on March 31, 2026. Tasks created
there no longer run. Thyme Flow runs the same kind of job: a TypeScript
function that reads the chain, decides, and returns the calls to send. Flow
sends them from a Safe the user owns, through a role limited to the contracts
and functions they allow.

This skill covers the translation. For the `thyme` CLI itself (deployment,
login, upload, executables, profiles, secrets) read the **thyme-flow** skill:
`https://flow.thymelabs.io/docs/skills/thyme-flow/SKILL.md`. Its rules apply
here too: never print credentials, a person approves logins and signs profile
changes, and ask before anything that sends transactions.

## 1. Inventory before you change anything

Search the repository and report what you find before porting:

```bash
grep -rln --exclude-dir=node_modules -e 'Web3Function.onRun' -e '@gelatonetwork/web3-functions-sdk' .
grep -rn --exclude-dir=node_modules -e 'createTask' -e 'createBatchExecTask' -e 'TriggerType' -e 'w3f deploy' .
grep -rn --include='*.sol' -e 'dedicatedMsgSender' -e 'AutomateReady' -e 'AutomateTaskCreator' -e '_getFeeDetails' .
```

For each Web3 Function, list:

| Item | Where to find it |
|---|---|
| Entry file | Usually `web3-functions/<name>/index.ts`. |
| Arguments | `schema.json` (`userArgs`) and `userArgs.json`. |
| Secrets | `context.secrets.get('KEY')` calls and the function's `.env`. |
| Storage keys | `storage.get` / `storage.set` calls. |
| Trigger | Task creation scripts (`TriggerType.TIME`, `CRON`, `EVENT`, `BLOCK`, interval values), deploy notes, or ask the user. |
| Chain | The network the task was created on, or ask the user. |
| Targets | Every `to` returned in `callData`, and the function each `data` encodes. |
| Contract coupling | Whether the target contract checks `dedicatedMsgSender` or pays Gelato fees. |

Then tell the user the plan: which functions port directly, which need a
decision (see section 5), and which one you will port first.

## 2. Translate the code

Create a Flow project if the repository has none (`thyme init`, then
`thyme new <name>` per function; see thyme-flow). Port one function at a time
into `functions/<name>/index.ts`.

| Gelato | Thyme Flow |
|---|---|
| `Web3Function.onRun(async (context) => { … })` | `export default defineTask({ schema, async run(ctx) { … } })` |
| `userArgs` typed by `schema.json` | `ctx.args`, typed by a Zod `schema`. Use `z.address()` for addresses and decimal strings for big integers. |
| `multiChainProvider.default()` (ethers) | `ctx.client`, a read-only viem `PublicClient` for the executable's chain. |
| `multiChainProvider.chainId(n)` | Not built in. Create a viem client with an RPC URL from a secret, or split the work into one executable per chain. |
| `await storage.get(key)` / `await storage.set(key, value)` | `ctx.storage.key` / `ctx.storage.key = value`. Plain JSON, not only strings. |
| `await context.secrets.get('KEY')` | `ctx.secrets.KEY` (a string map; check for missing values). |
| `gelatoArgs.chainId` | `await ctx.client.getChainId()` |
| `gelatoArgs.gasPrice` | `await ctx.client.getGasPrice()` |
| `gelatoArgs.blockTime` | `Math.floor(Date.now() / 1000)` or `(await ctx.client.getBlock()).timestamp` |
| `{ canExec: false, message }` | Unchanged. |
| `{ canExec: true, callData: [{ to, data }] }` | `{ canExec: true, calls: [{ to, data }] }` |
| `Web3Function.onSuccess` / `onFail` | `onSuccess(ctx, tx)` / `onFail(ctx, info)` next to `run`; also `onSkip` and `onError`. |
| `npx w3f test <file> --logs` with `userArgs.json` | `thyme run <name>` with `functions/<name>/args.json` |
| `npx w3f deploy` then create a task from the CID | `thyme upload <name> --tag v1`, then create an executable |

ethers v5 to viem:

| ethers | viem |
|---|---|
| `new Contract(address, abi, provider)` then `await c.method(a, b)` | `await ctx.client.readContract({ address, abi, functionName: 'method', args: [a, b] })` |
| `c.interface.encodeFunctionData('fn', [x])` | `encodeFunctionData({ abi, functionName: 'fn', args: [x] })` |
| Human-readable ABI strings | `parseAbi([...])` (keep the same strings) |
| `BigNumber`, `.toNumber()`, `.mul()` | native `bigint`, `Number(x)`, `x * y` |
| `utils.parseUnits` / `formatUnits` | `parseUnits` / `formatUnits` from viem |
| `provider.getBlockNumber()` | `ctx.client.getBlockNumber()` (returns `bigint`) |
| `contract.queryFilter(filter, from, to)` | `ctx.client.getContractEvents({ address, abi, eventName, fromBlock, toBlock })` |
| `ky` or `axios` | global `fetch` |

Keep the decision logic identical. Change only the entry point, the reads,
the encoding and the return field. Prefer `fetch`, viem and the SDK's `z`;
if the function needs another package, confirm that `thyme run` and
`thyme upload` both succeed with it.

Storage written by Gelato does not move. If the function depends on a stored
cursor or timestamp, ask the user for the last value and seed it in
`storage.json` locally, then with `thyme executables storage-set` after the
executable exists.

## 3. Map the trigger

| Gelato trigger | Flow |
|---|---|
| Time interval | `{ "type": "interval", "intervalMs": <ms> }`. Console presets run from 30 seconds to 24 hours, and the form accepts any interval of one second or more. Keep it longer than a run takes. |
| Cron | `{ "type": "cron", "cronspec": "<expression>" }` |
| On-chain event | An interval trigger. Read logs since a block cursor kept in `ctx.storage`, return `canExec: false` when there are none, and advance the cursor in `onSuccess`. |
| Every block | The shortest interval that meets the need. Say that runs are no longer per block. |
| Run once, or ad hoc | A webhook or `thyme executables run` (ask first). |

Keep each run bounded: a cloud run has about 30 seconds, and one run can
return up to 32 calls, sent as one atomic batch from a Roles profile.

## 4. Declare, test, ship

1. Write `functions/<name>/permissions.json` with every target and function
   signature the task can return.
2. Put the old `userArgs.json` values in `args.json`, set `RPC_URL` and
   `SIMULATE_ACCOUNT` in `.env`, and run `thyme run <name>` then
   `thyme run <name> --simulate`. Compare the decision with what the Gelato
   function would have returned for the same state.
3. Hand over to thyme-flow for login, `thyme upload`, the profile and the
   executable. The user must allow each target and selector on their Safe
   profile in the Console; tell them exactly which ones.
4. Create the executable with the trigger from section 3. Run
   `thyme executables simulate` before asking the user whether to resume or
   run it for real.

## 5. Things that need the user's decision

Stop and explain these instead of guessing:

- **Contracts that only accept Gelato.** A target that checks
  `dedicatedMsgSender` or uses `onlyDedicatedMsgSender` will reject calls from
  the Safe. The owner must allow the Safe address, through an existing setter or
  a contract upgrade.
- **Contracts that pay Gelato fees.** Functions built on `AutomateReady` that
  call `_getFeeDetails()` or `_transfer(fee, feeToken)` expect Gelato's
  executor. Flow pays gas itself. The contract may need a path without the fee
  transfer.
- **Calls with native value.** Flow calls are `{ to, data }` only. A call that
  sent ETH needs a different design, such as wrapping it in a contract call.
- **Several chains in one function.** One executable runs on one chain.
- **Unsupported chains.** Run `thyme chains list` to see what the deployment
  enables, and tell the user if their chain is missing.

## 6. Report back

For every function, tell the user: what changed, the args and trigger you
chose, the `permissions.json` entries, the local run result, and what they
must still do (approve login, allow targets on the Safe profile, top up dBank
credit for mainnet gas, update contract allowlists).
