Gelato Network

V1 to V2 migration guide

Web3 Functions V2 have been released, including new features and security enhancements. Here is a breakdown of what is new:
This migration guide explains the necessary steps for upgrading existing Web3 functions to the new V2 version. The Web3 functions hardhat template can also be consulted for reference. The guide consists of four sections:
  • upgrading dependencies
  • organizing Web3 Function projects
  • upgrading schema
  • code changes

Upgrading dependencies

Upgrade @gelatonetwork/web3-functions-sdk package to the latest version by running the following command:
yarn add @gelatonetwork/[email protected]

Organizing Web3 Function projects

  1. 1.
    Organize your web3 functions into their own folders.
  2. 2.
    Move Web3 Function specific secrets to its own .env file. Remove SECRET_ prefixes from secret names, it's no longer needed.
  1. 3.
    User arguments can be specified in the userArgs.json file. Those arguments are only passed during testing of the Web3 Function, actual arguments will still be requested during task creation.
"currency": "ethereum",
"oracle": "0x71B9B0F6C999CBbB0FeF9c92B80D54e4973214da"
  1. 4.
    Each Web3 Function should have its own userArgs.json, schema.json and .env files within its own folder. The file structure should look something like this:
├── src/
│ ├── web3-functions/
│ │ └── oracle/ // web3 function folder
│ │ ├── index.ts // web3 function
│ │ ├── schema.json // web3 function schema
│ │ └── userArgs.json // web3 function user arguments (for testing)
│ │ └── .env // web3 function specific secrets
│ └── ...
├── package.json
└── .env

Upgrading schema

  1. 1.
    Upgrade your web3 function's schema version, web3FunctionVersion to 2.0.0:
"web3FunctionVersion": "2.0.0",
"runtime": "js-1.0",
"memory": 128,
"timeout": 30,
"userArgs": {
"currency": "string",
"oracle": "string"

Code changes

  1. 1.
    The new version of the Web3 Function allows for invoking multiple contracts with different payloads in a single execution. The callData returned by the Web3 Function must be updated to specify a list of target contracts with their related call data:
return {
canExec: true,
callData: [
to: oracleAddress,
data: oracle.interface.encodeFunctionData("updatePrice", [price]),
to: oracleAddress2,
data: oracle.interface.encodeFunctionData("updatePrice", [price2])
  1. 2.
    Web3 Function context now provides a multi-chain provider, thus update the provider in Web3 Function with multiChainProvider. The provider for the network on which the task is created can be accessed using multiChainProvider.default().
Web3Function.onRun(async (context: Web3FunctionContext) => {
const { userArgs, multiChainProvider } = context;
const provider = multiChainProvider.default()
const goerliProvider = multiChainProvider.chainId(5);
const ethereumProvider = multiChainProvider.chainId(1);
  1. 3.
    gelatoArgs.blockTime is not available anymore, if it was used previously block time can be fetched with the following:
const blockTime = (await provider.getBlock("latest")).timestamp;