Creating Web3 Function Tasks
Configuring what triggers your Web3 Function to run and the target smart contract to execute
Last updated
Configuring what triggers your Web3 Function to run and the target smart contract to execute
Last updated
A Web3 Function Task links your Web3 Function to your target smart contract and enables you to configure what should trigger your Web3 Function to execute, any arguments you want to pass to it and the target smart contract to execute.
In order to create a task that will automatically run your Web3 Function on your behalf, go to https://beta.app.gelato.network/ and click on the "Create Task" button.
You will be invited to select what should trigger your Web3 Function:
Select the time interval between Web3 Function runs that you would like to schedule. The minimum interval is currently 5 seconds. You can also set a timestamp (in UTC) in the future when you'd like executions to commence. By default runs start immediately after the task is created.
You can alternatively use any standard Cron expression to specify when you want your Web3 Function. Cron does not support sub-minute frequencies.
If your Web3 function triggers a transaction execution, further runs of your function will be paused until the transaction is confirmed on chain. When confirmed your Web3 Function runs will resume as configured.
Make sure to have the IPFS CID of your Web3 Function at hand and paste it into the respective input. We fetch your Web3 Function and enable you to review the source code and enter any arguments that you have created:
Select the network on which your task should execute:
If you select a network that your wallet is not currently connected to you will be prompted to switch to the target network.
If your task uses secrets
to store any private credentials, you can then configure the secret variables that will be exposed in your web3 function:
Secrets are optional, leave this part empty if your web3 function is not using any private credentials.
Finally, you will be prompted to enter a name for your task. Click on "Create Task" and confirm your name and task creation using your wallet:
You will then be redirected to the task page where you can view logs, past executions and more task-related information.
You can create a task that uses Web3 Function from your smart contract as well. Learn more about creating tasks via smart contract.
Web3 Function secrets are not available for smart contract created tasks.
To create a Web3 Function task with your smart contract, you can inherit AutomateTaskCreator
which has helper functions to easily create your task.
Pass the Module.PROXY
& Module.WEB3_FUNCTION
as modules in ModuleData
Use _web3FunctionModuleArg
to encode arguments for WEB3_FUNCTION
module.
Here is how you can encode your Web3Function arguments to get web3FunctionArgsHex.
In this example, the Web3Function has 2 arguments, counterW3fAddress
& count
.
In your contract, you would encode the arguments according to the sequence defined in schema.json
.
The full code can be found here.
Use the automate-sdk
to easily create a new task:
Make sure to use the beta
version of the automate-sdk
to have access to web3 functions method
Import the sdk and create task, passing your web3 function CID & arguments:
If your task utilizes secrets, you can set them after the task has been created.
You can see a live example in our web3-functions-hardhat-template
repo